private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 434, 261);
frame.getContentPane().add(panel);
panel.setLayout(null);
JCheckBox chckbxCheckbox = new JCheckBox("checkbox");
chckbxCheckbox.setBounds(44, 41, 97, 23);
panel.add(chckbxCheckbox);
JCheckBox chckbxCheckbox_1 = new JCheckBox("checkbox 2");
chckbxCheckbox_1.setBounds(197, 41, 97, 23);
panel.add(chckbxCheckbox_1);
}
Basically, I want chckbxCheckbox
, to alter the state of chckbxCheckbox_1
. After an alteration, the code section looks like this:
JCheckBox chckbxCheckbox = new JCheckBox("checkbox");
chckbxCheckbox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
chckbxCheckbox_1.setEnabled(false);
}
});
chckbxCheckbox.setBounds(44, 41, 97, 23);
panel.add(chckbxCheckbox);
JCheckBox chckbxCheckbox_1 = new JCheckBox("checkbox 2");
chckbxCheckbox_1.setBounds(197, 41, 97, 23);
panel.add(chckbxCheckbox_1);
I get the following:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
chckbxCheckbox_1 cannot be resolved
The Question becomes, how to I work with components that appear lower in the code? Again, this is just an example code. The code I'm working on has a lot more components interacting with each other in ways that would eventually prevent me from moving code around to avoid this issue.