Setting Up the Button to Switch Color

In this section, you specify an event (a mouse click) to which the button can respond.

To add the mouse event:

  1. In the Component Inspector, select the jButton1 node (if it is not already selected).
  2. Click the Events tab at the bottom of the Properties pane.
  3. In the Events pane, scroll to the mouseClicked property and click.

    The value changes from none to jButton1MouseClicked.

  4. Press Enter.

    The listener code jButton1.addMouseListener and event method jButton1MouseClicked() automatically appear in the Source Editor.

Next:  Adding Event Handler Code
Back:  Adding a Button

Legal Notices