
/**
 * A simple demonstration of ActionListeners
 * 
 * @author Russell C. Bjork
 * @version March 3, 2008
 */

import java.awt.*;
import javax.swing.*;

public class ActionListenerDemo extends JFrame
{
    public static void main(String [] args)
    {
        new ActionListenerDemo().setVisible(true);
    }
    
    public ActionListenerDemo()
    {
        setLayout(new FlowLayout());
        
        // Create the buttons
        
        JButton helloButton = new JButton("Say hello");
        add(helloButton);
        JButton goodbyeButton = new JButton("Say goodbye");
        add(goodbyeButton);
        
        // Create the menu
        
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        JMenu sayMenu = new JMenu("Say");
        menuBar.add(sayMenu);
        JMenuItem helloItem = new JMenuItem("Hello");
        sayMenu.add(helloItem);
        JMenuItem goodbyeItem = new JMenuItem("Goodbye");
        sayMenu.add(goodbyeItem);
        
        // Set the GUI to the correct size
        
        pack();

        // Add action listeners to the various components
        
        helloButton.addActionListener(new SayHello());
        goodbyeButton.addActionListener(new SayGoodbye());
        helloItem.addActionListener(new SayHello());
        goodbyeItem.addActionListener(new SayGoodbye());
    }
}
