Java Reference
In-Depth Information
Let's take a close look at the new things in this program. First, notice that the program
now imports both the java.awt and java.awt.event packages. The java.awt package is
needed because it contains the FlowLayout class, which supports the flow layout manager.
The java.awt.event package is needed because it defines the ActionListener interface and
the ActionEvent class.
Next, the class ButtonDemo is declared. Notice that it implements ActionListener . This
means that ButtonDemo objects can be used to receive action events. Next, a JLabel ref-
erence is declared. This reference will be used within the actionPerformed( ) method to
display which button has been pressed.
The ButtonDemo constructor begins by creating a JFrame called jfrm . It then sets the
layout manager for the content pane of jfrm to FlowLayout , as shown here:
Search WWH ::




Custom Search