1. set the jButton2 visibility to false in the initComponents method.
2. fix the jButton1ActionPerformed method as follows:
.....jButton1ActionPerformed(ActionEvent ae) {
boolean isVisible = jButton2.isVisible();
jButton2.setVisible(!isVisible);
}
This will toggle the jButton2 on and off.
The other thing that you can do using the JToggleButton instead
of jButton1.