You are here:

Java/GUI Multiple Handlers

Advertisement


Question
Hello, my friend asked me to make a program that allows you to play music.  But rather than that I'm making a program that runs anything.  It's very basic and I've been working on it for a day and a half now.  But I've ran into a problem.  I have 3 different JCheckBoxes and I'm trying to be able to update them all at the same time using a basic ItemListener and I'm having trouble with it.  Here's my code for my Gui class:

http://pastebin.com/bMp5gwJc

How would I be able to make it work so that I'm able to update filepath by clicking on any of the checkboxes, rather than what it does now(Only works if I click on the desktopbutton because it runs it calls upon that one first.)

Hope you can think of a solution, thanks!

Answer
Here is a slightly fixed up version of your code:
http://pastebin.com/YHbbE7Ny

Note that using check boxes in this case doesn't make any sense unless you plan to allow multiple locations. Also, you are making the assumption in your code that the user:
1. Uses Windows 6 or higher
2. Their user name is the same as their user folder
3. That it is located on the c drive.

A better approach is to use a JFileChooser to let the user select a file (or directory if you turn that option on).

Java

All Answers


Answers by Expert:


Ask Experts

Volunteer


Artemus Harper

Expertise

I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.

Experience

I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Organizations
Washington State University

Education/Credentials
MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2016 About.com. All rights reserved.