Java Reference
In-Depth Information
66
public void
setVisible(
boolean
visible) {
67 frame.setVisible(visible);
68 }
69
70 // used for timer that repeatedly repaints screen
71
public void
actionPerformed(ActionEvent e) {
72 panel.repaint();
73 }
74
75 // draws status bar text when mouse moves
76
public void
mouseMoved(MouseEvent e) {
77 statusBar.setText("(" + e.getX() + ", " +
78 e.getY() + ")");
79 }
80 }
This version of the code can be used to draw any of the example programs from
Supplement 3G. For example, the following screenshot shows the output when the
Pyramids case study from Supplement 3G is run using the
DrawingPanel
we have
just implemented:
Chapter Summary
A graphical user interface (GUI) has a window frame that
contains buttons, text input fields, and other onscreen
components.
Some of the most common graphical components are but-
tons (
JButton
objects), text input fields (
JTextField
objects), and text labels (
JLabel
objects).
The
JOptionPane
class is a simple GUI class that can be
used to display messages and prompt a user to input val-
ues, enabling graphical output and input.
All graphical components in Java belong to a common
inheritance hierarchy, so they share a common set of
methods that can be used to get and set properties such as
background color, size, and font.
Search WWH ::
Custom Search