import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

class ButtonPanel extends JPanel implements ActionListener
{
    public ButtonPanel()
    {
        helloButton = new JButton("Hello");
        goodbyeButton = new JButton("Good Bye");
        textLabel = new JLabel();
        
        helloButton.addActionListener(this);        // Register us as a listener
        goodbyeButton.addActionListener(this);      // for button actions.
        
        add(helloButton);
        add(goodbyeButton);
        add(textLabel);
    }
    
    public void actionPerformed(ActionEvent e)
    {
        Object src = e.getSource();
        if (src == helloButton)
        {   textLabel.setText("Hello!"); }
        else if (src == goodbyeButton)
        {   textLabel.setText("Good Bye!"); }
        else System.out.println("Nothing to do!");
    }
    
    private JButton helloButton;
    private JButton goodbyeButton;
    private JLabel textLabel;    
}

class ButtonFrame extends JFrame
{
    public ButtonFrame()
    {   setTitle("Button Test");
        setSize(175, 125);
        addWindowListener(new WindowAdapter()
        {  public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
        } );
        Container contentPane = getContentPane();
        contentPane.add(new ButtonPanel());
    }
}

public class ButtonTest
{  public static void main(String[] args)
   {  JFrame frame = new ButtonFrame();
      frame.show();  
   }
}
