Java Reference
In-Depth Information
LISTING 4.10
continued
frame.getContentPane().add( new PushCounterPanel());
frame.pack();
frame.setVisible( true );
}
}
DISPLAY
The components used in this program include a button, a label to display the
count, a panel to organize the GUI, and a frame to display the panel. The panel is
defined by the PushCounterPanel class, shown in Listing 4.11.
A push button is a component that allows the user to initiate an action with a
press of the mouse. There are other types of button components that we explore
in later chapters. A push button is defined by the JButton class.
LISTING 4.11
//********************************************************************
// PushCounterPanel.java Author: Lewis/Loftus
//
// Demonstrates a graphical user interface and an event listener.
//********************************************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PushCounterPanel extends JPanel
{
private int count;
private JButton push;
private JLabel label;
 
Search WWH ::




Custom Search