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

public class Window extends JFrame implements ActionListener {

    public static void main(String[] args) {
        Window w = new Window();
    }

    JTextField f1 = new JTextField("enter text here...");

    public Window() {
        super("My awesome window");
        this.setSize(800, 600);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        JPanel buttonBar = new JPanel(new FlowLayout());
        JButton b1 = new JButton("Click me");
        b1.addActionListener(this);
        JButton b2 = new JButton("Test 2");
        b2.addActionListener(this);
        JButton b3 = new JButton("Test 3");
        b3.addActionListener(this);
        JButton b4 = new JButton("Test 4");
        b4.addActionListener(this);

        buttonBar.add(b1);
        buttonBar.add(b2);
        buttonBar.add(b3);
        buttonBar.add(b4);

        JPanel fieldBar = new JPanel(new FlowLayout());

        JTextField f2 = new JTextField("again");
        JTextField f3 = new JTextField("and again");

        fieldBar.add(f1);
        fieldBar.add(f2);
        fieldBar.add(f3);

        JPanel topPanel = new JPanel(new GridLayout(3, 1));
        topPanel.add(buttonBar);
        topPanel.add(fieldBar);

	/* DisplayPanel is some other JPanel subclass that the expression tree
	 * is drawn on. A useful reference to base your DisplayPanel on:
	 * http://www.cs.columbia.edu/~allen/S14/NOTES/DisplaySimpleTree.java
	 * You can comment out the DisplayPanel lines if you want to try
	 * compiling this code.
         */
        DisplayPanel someOtherPanel = new DisplayPanel();
        this.getContentPane().add(topPanel, BorderLayout.NORTH);
        this.getContentPane().add(someOtherPanel, BorderLayout.SOUTH);

        this.pack();
        this.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        String action = e.getActionCommand();
        if (action.equals("Click me")) {
            f1.setText("Yay you clicked the button");
        } else if (action.equals("Test 2")) {
            foo(f1.getText());
        }
    }

    public void foo(String s) {
        System.out.println(s);
    }
}
