My problem is with ItemListener I'm not sure why it is not working. Well I'm trying to split the ItemListener
into two class.
in the main class I have this
final JCheckBox whole_C_CheckBox = new JCheckBox("Whole"); whole_C_CheckBox.addItemListener(new CheckBox(whole_C_QTextField, whole_C_WTextField, whole_C_PTextField)); whole_C_CheckBox.setVerticalAlignment(SwingConstants.BOTTOM); whole_C_CheckBox.setHorizontalAlignment(SwingConstants.LEFT); whole_C_CheckBox.setBounds(12, 66, 113, 25); chikenPanel.add(whole_C_CheckBox);
In the other class I have
public class CheckBox implements ItemListener{ private JTextField q; private JTextField p; private JTextField w; private JCheckBox whole_C_CheckBox; public CheckBox(JTextField whole_C_QTextField, JTextField whole_C_WTextField, JTextField whole_C_PTextField) { this.q = whole_C_QTextField; this.w = whole_C_WTextField; this.p = whole_C_PTextField; } @Override public void itemStateChanged(ItemEvent e) { if(whole_C_CheckBox.isSelected()){ q.setText(""); w.setText(""); p.setText(""); } else{ q.setText("0"); w.setText("0.00"); p.setText("0.00"); } }}
will when I try to run the program its working.However, when I click on the Check Box for (whole_C_CheckBox ) it give an error I don't know what is wrong with my code.
Note: in the main class all these whole_C_QTextField, whole_C_WTextField, whole_C_PTextField has
been set in default to (0, 0.00, 0.00), so I'm trying when I click on Check Box for (whole_C_CheckBox )
it will set them to nothing, and if I unchecked them again they will return to their default (0, 0.00, 0.00).