Solved

adding to list from checkboxs

Posted on 2004-04-15
3
225 Views
Last Modified: 2010-03-31
In this section of the code [ addToList(bList, ???); ] an audiofile is added, this file will come from a checkbox being checked. How would this code add the audiofile to the blist in the following piece of code (addToList(bList, ???);) if I named the checkboxs 2sec-12sec.   I got this code from objects.

addToList(bList, ???);


public class MyListener implements ActionListener {

    private List aList = new ArrayList();
    private List bList = new ArrayList();

    public MyListener() {
    }

    public void addButton(JButton theButtonToAdd) {
       theButtonToAdd.addActionListener(this);  // Listen for the button to be pressed
    }

    public void actionPerformed(ActionEvent e) {
       JButton button = (JButton)e.getSource();
       String command = button.getActionCommand();
       addToList(aList, command);
       addToList(bList, ???);
    }

    private static List list, String file) {
       if (list.contains(file))
       {
          list.remove(file);
       }
       else
       {
          list.add(file);
       }
    }

    public List getAList() { return aList; }
    public List getBList() { return bList; }

}
0
Comment
Question by:Drop_of_Rain
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10839021
it already is adding the file to the blist, I just wasn't sure where the filename was coming from.
0
 

Author Comment

by:Drop_of_Rain
ID: 10839060
No, I know it was adding it I'm just looking to ad it from a checkbox know that I have figured out what I need to do next in the custom section of the program.
0
 
LVL 92

Accepted Solution

by:
objects earned 350 total points
ID: 10839070
the following will allow you to use the class with both JButton's and JCheckBox's.

public class MyListener implements ActionListener {

    private List aList = new ArrayList();
    private List bList = new ArrayList();

    public MyListener() {
    }

    public void addButton(AbstractButton theButtonToAdd) {
       theButtonToAdd.addActionListener(this);  // Listen for the button to be pressed
    }

    public void actionPerformed(ActionEvent e) {
       AbstractButton button = (AbstractButton)e.getSource();
       String command = button.getActionCommand();
       addToList(aList, command);
       addToList(bList, ???);
    }
...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java. non-English characters encoding problem. intellij idea 3 74
create a gui in perl 3 72
windows explorer path to command prompt 5 33
difference of if loops 23 41
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now