-
Help with JCheckBox
So, what I'm trying to do here is have the system print "test" when a JCheckBox from my GUI is checked.
Code:
Code:
foodcheck.addActionListener(this);
//I added an action listener to the checkbox
later down:
Code:
if (foodcheck.isSelected()) {
System.out.print("test");
}
foodcheck is the JCheckBox.
Help please!
-
Re: Help with JCheckBox
Try doing the method Code:
public void actionPerformed(ActionEvent e) {
System.out.print("test");
}
Good Luck!
-
Re: Help with JCheckBox
Quote:
Originally Posted by
MW130
Try doing the method
Code:
public void actionPerformed(ActionEvent e) {
System.out.print("test");
}
Good Luck!
No, this will print any time the check box is checked, regardless if it has been unselected or selected. The best solution is to read the check box tutorial and add an ItemListener as demonstrated in the tutorial.