I have one small problem with swing. I have 2 buttons. One visible and one not
visible. If i click on the visible one, I want to set the second one visible
too. I attached the source code. For sure I made one mistake, but where?
public class TestSetVisible extends javax.swing.JFrame {
/** Creates new form TestSetVisible */
public TestSetVisible() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
jButton2.setText("jButton2");
jButton2.setEnabled(false);
jPanel1.add(jButton2);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
jButton2.setVisible(true);
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new TestSetVisible().show();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}