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

public class TwoButtons extends JApplet implements ActionListener
{
  FlowLayout flow = new FlowLayout();
  JButton buttonOne = new JButton("Button 1");
  JButton buttonTwo = new JButton("Button 2");
  JLabel iSawThat = new JLabel("Press a button.");

  public void init()
  {
    Container con = getContentPane();
    con.setLayout(flow);
    con.add(buttonOne);
    con.add(buttonTwo);
    con.add(iSawThat);
    
    buttonOne.addActionListener(this);
    buttonTwo.addActionListener(this);
  }

  public void actionPerformed(ActionEvent thisEvent)
  {
    Object source = thisEvent.getSource();
    if(source == buttonOne)
    {
      iSawThat.setText("Button 1 was pressed.");
    }
    else if(source == buttonTwo)
    {
      iSawThat.setText("Button 2 was pressed.");
    }
    repaint();
  }
}
Hosted by www.Geocities.ws

1