I have created the simple application below. A JFrame with a single button. When the button is clicked the line
jButton1.setEnabled(false);
should disable the button.
The button does get shaded out but continues to work with the System.out.println("Mouse Pressed"); line still printing the message to the screen when the button is pressed.
Please tell me why this happens?
package editable;
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
this.setBounds(20, 20, 400, 400);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
jButton1.setText("jButton1");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton1MousePressed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(131, 112, 73, 23);
pack();
}// </editor-fold>
private void jButton1MousePressed(java.awt.event.MouseEvent evt) {
jButton1.setEnabled(false);
System.out.println("Mouse Pressed");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
NewJFrame njf = new NewJFrame();
njf.setVisible(true);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}