Disabling Check Boxes created by different method.
So. I have the following method that is called to create Check Boxes:
Code :
//function to create check boxes and add them to frame ( complete with action listeners )
public void addCheckButton(int i){
String ButtonNum = Integer.toString(i);
JCheckBox select = new JCheckBox(ButtonNum);
select.setBackground(new Color(56,48,44));
select.setForeground(new Color(225,255,255));
con.add(select);
select.addActionListener(this);
}
I am creating these buttons in my implemention like so:
Code :
//add our check-buttons
for (int i=0; i<35; i++){
lottery.addCheckButton((i+1));
}
I want to disable all of my created checkboxes when 6 are selected. I am using the action listener event like so:
Code :
public void actionPerformed(ActionEvent evt) {
//String Action= evt.paramString();
this.check_six++;
if (this.check_six<=6){
JOptionPane.showMessageDialog(frame, "Action id: " + check_six);
}
else {
JOptionPane.showMessageDialog(frame, "MAX");
//DISABLE CHECK BUTTONS HERE!
}
}
Does any one have a solution for this that would work with my current setup?
thx
Re: Disabling Check Boxes created by different method.
You have to keep a reference to the checkboxes you want to disable, then iterate over them and disable them when appropriate.
Re: Disabling Check Boxes created by different method.
I see. So would this pretty much require me making a class scope variable?
Re: Disabling Check Boxes created by different method.
Quote:
Originally Posted by
xdega
I see. So would this pretty much require me making a class scope variable?
That's one way to do it. Or you could pass the reference around as a parameter to the necessary method(s).