682 Graphical User Interface Components: Part 1 Chapter (Web design tools)
Sunday, February 10th, 2008682 Graphical User Interface Components: Part 1 Chapter 12 Fig. 12.17 Fig. 12.17 Demonstrating mouse event handling (part 3 of 3). Each mouse event results in a String displayed in JLabel statusBar at the bottom of the window. Lines 21 22 in the constructor define JLabelstatusBarand attach it to the content pane. Until now, each time we used the content pane, method setLayoutwas called to set the content pane s layout manager to a FlowLayout. This allowed the content pane to display the GUI components we attached to it from left to right. If the GUI components do not fit on one line, the FlowLayoutcreates additional lines to continue displaying the GUI components. Actually, the default layout manager is a BorderLayoutthat divides the content pane s area into five regions north, south, east, west and center. Line 22 uses a new version of Containermethod addto attach statusBarto the region Border- Layout.SOUTH, which extends across the entire bottom of the content pane. We discuss BorderLayoutand several other layout managers in detail later in this chapter. Lines 25 26 in the constructor register the MouseTrackerwindow object as the listener for its own mouse events. Methods addMouseListener and addMouse- MotionListener are Component methods that can be used to register mouse event listeners for an object of any class that extends Component. When the mouse enters or exits the application area, method mouseEntered (lines 56 59) and method mouseExited(lines 62 65) are called, respectively. Method mouse- Exiteddisplays a message in statusBarindicating that the mouse is outside the application (see the first sample output window). Method mouseEntered displays a message dialog box indicating that the mouse entered the application window. [Note: Be sure to press Enter to dismiss the message dialog, rather than using the mouse. If you use the mouse to dismiss the dialog, when you move the mouse over the window again, mouseEnteredredisplays the dialog. This will prevent you from trying the other mouse events.] Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01