Java Reference
In-Depth Information
public void mouseExited (MouseEvent e) {
saySomething ( " Mouse exited " , e);
}
public void mouseClicked (MouseEvent e) {
saySomething ("Mouse clicked (# of clicks: "
+ e.getClickCount () + ")", e);
}
/** On JTextArea print messages describing mouse events. **/
void saySomething (String event - description, MouseEvent e){
fTextOutput.insert (event - description + " detected on "
+ e.getComponent ().getClass ()
.getName () + " . " + "\ n " ,0);
}
} // class CaptureEventPanel
7.3 More user interface components
Now that we know how to handle events, we introduce four more event-generating
components. In each of the cases discussed here, two panels are displayed on an
applet. The OutputPanel simply displays a solid color. The other panel contains
the UI components that set the color of OutputPanel . The components that we
discuss are:
JCheckBox
JRadioButton
JList
JSlider
In the four sections that follow, we create JPanel subclasses that hold the above
components. First we show the code for the program UiTestApplet ,which
selects one of these panels according to a parameter passed from the applet tag
in the web page. It then displays both the selected panel and OutputPanel ,
whose code is also shown below.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Display one of four types of component panels
*tocontrol the background color on a separate panel.
* Applet parameter selects the type of panel. **/
Search WWH ::




Custom Search