import java.awt.*;
import java.awt.event.*;

/** Taken from Core Web Programming from 
 *  Prentice Hall and Sun Microsystems Press,
 *  http://www.corewebprogramming.com/.
 *  &copy; 2001 Marty Hall and Larry Brown;
 *  may be freely used or adapted.
 */

public class ActionExample2 extends CloseableFrame
                            implements ActionListener {
  public static void main(String[] args) {
    new ActionExample2();
  }

  private Button button1, button2, button3;

  public ActionExample2() {
    super("Handling Events in Other Object");
    setLayout(new FlowLayout());
    setFont(new Font("Serif", Font.BOLD, 18));
    button1 = new Button("Resize to 300x200");
    button2 = new Button("Resize to 400x300");
    button3 = new Button("Resize to 500x400");
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    add(button1);
    add(button2);
    add(button3);
    setSize(400, 300);
    setVisible(true);
  }

  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == button1) {
      updateLayout(300, 200);
    } else if (event.getSource() == button2) {
      updateLayout(400, 300);
    } else if (event.getSource() == button3) {
      updateLayout(500, 400);
    }
  }
  
  private void updateLayout(int width, int height) {
    setSize(width, height);
    invalidate();
    validate();
  }
}
