Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For making changes you can add <code>ItemListener</code> to your <code>JCheckBox</code> and <code>JRadioButtons</code> and for <code>JTextField</code> you can add <code>CaretListener</code>.</p> <p>This small program might help you :</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.CaretListener; import javax.swing.event.CaretEvent; public class StateChangedEventClass extends JFrame { private JPanel contentPane, panel1, panel2; private JButton clearButton; private ItemListener itemChangeAction; private CaretListener caretAction; public StateChangedEventClass() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setLayout(new GridLayout(2, 2)); clearButton = new JButton("CLEAR"); clearButton.setEnabled(false); itemChangeAction = new ItemListener() { public void itemStateChanged(ItemEvent ce) { clearButton.setEnabled(true); } }; caretAction = new CaretListener() { public void caretUpdate(CaretEvent ce) { clearButton.setEnabled(true); } }; panel1 = new JPanel(); panel1.setLayout(new GridLayout(2 , 2)); JLabel userLabel = new JLabel("USERNAME : ", JLabel.CENTER); JTextField userField = new JTextField(10); userField.addCaretListener(caretAction); JLabel passLabel = new JLabel("PASSWORD : " + JLabel.CENTER); JTextField passField = new JTextField(10); passField.addCaretListener(caretAction); panel1.add(userLabel); panel1.add(userField); panel1.add(passLabel); panel1.add(passField); contentPane.add(panel1); panel2 = new JPanel(); panel2.setLayout(new GridLayout(2, 1)); JRadioButton maleButton = new JRadioButton("MALE", false); maleButton.addItemListener(itemChangeAction); JRadioButton femaleButton = new JRadioButton("FEMALE", false); femaleButton.addItemListener(itemChangeAction); ButtonGroup bg = new ButtonGroup(); bg.add(maleButton); bg.add(femaleButton); panel2.add(maleButton); panel2.add(femaleButton); contentPane.add(panel2); add(contentPane, BorderLayout.CENTER); add(clearButton, BorderLayout.PAGE_END); pack(); setVisible(true); } public void caretUpdate(CaretEvent ce) { clearButton.setEnabled(true); } public static void main(String... args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new StateChangedEventClass(); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload