I have this code block setup within my program (extracte to this test class)
I want to be able to disable the input JTextField and the JButton if no
JCheckboxes are selected,
though if one is selected i want to enable the input JTextField and start
JButton.
What am I doing stupidly wrong here..... I feel such an idiot for having to
ask this question in this NG
thankyou for pointing out my stupidity (error)
########
CODE
########
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
public class Test extends JFrame{
protected JPanel cbPan, inPan;
protected JCheckBox [] chqBox = new JCheckBox[6];
protected String [] chqBxStr = {"CK1","CK2","CK3","CK4","CK5","CK6"};
protected JTextField input;
protected JButton start;
public Test() {
setSize(300,200);
cbPan = new JPanel(new GridLayout(3,2));
cbPan.setBorder(new CompoundBorder(new EtchedBorder(),
new EmptyBorder(2, 0, 2, 5)));
for (int i = 0; i < 6; i++) {
final int j = i;
chqBox[j] = new JCheckBox(chqBxStr[j]);
chqBox[j].setActionCommand(chqBxStr[j]);
ActionListener act = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == chqBxStr[j]) {
if (chqBox[j].isSelected() == true) {
input.setEnabled(true);
start.setEnabled(true);
}
}
for (int i = 0; i < 6; i++) {
if (chqBox[i].isSelected() == false) {
input.setEnabled(false);
start.setEnabled(false);
}
}
}
};
chqBox[j].addActionListener(act);
cbPan.add(chqBox[j]);
}
inPan = new JPanel(new GridLayout(0,1));
inPan.setBorder(new CompoundBorder(new EtchedBorder(),
new EmptyBorder(5,25,10,25)));
input = new JTextField("1000");
start = new JButton("Start");
ActionListener act = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//ACTIONS HERE
}
};
input.addActionListener(act);
start.addActionListener(act);
inPan.add(input);
inPan.add(start);
input.setEnabled(false);
start.setEnabled(false);
getContentPane().add( BorderLayout.NORTH,cbPan);
getContentPane().add( BorderLayout.SOUTH,inPan);
}
public static void main(String[] args) {
Test frame = new Test();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Paul Lutus - 20 Oct 2004 06:56 GMT
> I have this code block setup within my program (extracte to this test
> class)
[quoted text clipped - 6 lines]
> What am I doing stupidly wrong here..... I feel such an idiot for having
> to ask this question in this NG
Please tell us:
1. What you expected.
2. What you got instead.
3. How they differ.

Signature
Paul Lutus
http://www.arachnoid.com
Russell - 20 Oct 2004 07:01 GMT
> > What am I doing stupidly wrong here..... I feel such an idiot for having
> > to ask this question in this NG
>
> Please tell us:
>
> 1. What you expected.
I want to be able to disable the input JTextField and the JButton if no
JCheckboxes are selected,
though if one is selected i want to enable the input JTextField and start
JButton.
> 2. What you got instead.
not what i desired..see above
> 3. How they differ.
see above
Paul Lutus - 20 Oct 2004 07:15 GMT
>> > What am I doing stupidly wrong here..... I feel such an idiot for
>> > having to ask this question in this NG
[quoted text clipped - 11 lines]
>
> not what i desired..see above
What did you get instead? "Not what I desired" is not an answer.
>> 3. How they differ.
>
> see above
How do they differ? "See above" is not an answer.
Do you want someone to take the time to help you? Take the time to provide
useful information.

Signature
Paul Lutus
http://www.arachnoid.com
Russell - 20 Oct 2004 07:37 GMT
what i got/get with the fully working code i supplied (though not what i
desired) with my original query was:
1) when all check boxes are checked, the input JTextField and start JButton
are enabled.
2)disable 1 checkbox and the input and start components are disabled.
what i want is
1)when one check box is checked, the input and start components get enabled.
2)no matter if all or only one checkbox('s) is selected, i want the input
and start components to remain enabled "unless" all checkboxes are
un-selected
hope that helps clear up any mis-understanding
thankyou......
Russell - 20 Oct 2004 10:33 GMT
sorted..... no need for assitance now....thanks anyway