import java.awt.*;
import java.awt.event.*;

    // Example showing a listener to multiple buttons.
    // Use the event's source to detect which was pressed.
class MultiButtonFrame3 extends Frame implements ActionListener {

    public MultiButtonFrame3(){
        final int width = 200, height = 200;
        setSize(width,height);

        // Add the two buttons to the frame.
        Button top = getTop();
        top.addActionListener(this);
        add(top,"North");

        Button button = getBottom();
        bottom.addActionListener(this);
        add(bottom,"South");
    }

        // Work out which button was pressed.
    public void actionPerformed(ActionEvent e){
        Object source = e.getSource();

        if(source == getTop()){
            Button b = (Button) source;
            System.out.println(b.getLabel()+" pressed.");
        }
        else if(source == getBottom()){
            Button b = (Button) source;
            System.out.println(b.getLabel()+" pressed.");
        }
        else{
            System.out.println("Unexpected event from: "+source);
        }
    }

    protected Button getTop(){
        return top;
    }

    protected Button getBottom(){
        return bottom;
    }

    // Two buttons within the frame.
    private final Button top = new Button("Top"),
                         bottom = new Button("Bottom");
}
