Now that the jButton1MouseClicked() method has been created, you can add custom code for handling this event. You want a click of the button to change the color of the label.
To add the code:
//End of variables declaration
(on or about line 76), declare a new
variable:
private java.awt.Color currentColor = java.awt.Color.lightGray;
To use the dynamic code completion feature in the Source Editor, type the first few characters. Select the completed term from the displayed list of classes, methods, and variables, and press Enter.
if (currentColor == java.awt.Color.lightGray) currentColor = java.awt.Color.gray; else if (currentColor == java.awt.Color.gray) currentColor = java.awt.Color.black; else currentColor = java.awt.Color.lightGray; jLabel1.setBackground (currentColor);
Next: Compiling and Running Your Program
Back: Setting Up the Button to Switch Color |