In this section, you use the IDE's Source Editor.
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;
![]() |
The cursor's location in the Source Editor window is indicated by
the line and row numbers found in the bottom left corner
of the window. The format is line:row .
|
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 |
See also | |
---|---|
Editing Source Files
Managing Component Events |