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

// Thu Oct 21 18:07:43 EST 2004
// Written by Sean R. Owens, sean at guild dot net, released to the
// public domain.  Share and enjoy.  Since some people argue that it is
// impossible to release software to the public domain, you are also free
// to use this code under any version of the GPL, LPGL, or BSD licenses,
// or contact me for use of another license.

// Very simple actionExample
public class ActionExample extends JFrame implements ActionListener {
    private final static String ACTION_ONE_TEXTFIELD = "ONE";
    private final static String ACTION_MANY_TEXTFIELDS = "MANY";
    private JPanel topPanel = null;
    private JScrollPane scrollableTextArea = null;
    private JTextField text1 = null;
    private JTextField text2 = null;
    private JTextField text3 = null;
    private JTextField text4 = null;
    private JTextField text5 = null;
    private JTextField text6 = null;
    private JTextField text7 = null;
    private JTextField text8 = null;
    private JTextField text9 = null;
    private JButton button1 = null;
    private JButton button2 = null;

    public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if(ACTION_ONE_TEXTFIELD == command) { 
            System.err.println("Displaying scrollable text area.");
        else if(ACTION_MANY_TEXTFIELDS == command) { 
            System.err.println("Displaying text fields.");

    public ActionExample() {
        super("Action Example");
        addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {System.exit(0);}
        // For some reason I don't understand, if I just use 0,0 here
        // (the top left of the screen), xwin-32 puts the window
        // slightly off the screen to the top and the left.

        topPanel = new JPanel();
        topPanel.setLayout( new BorderLayout() );
        getContentPane().add( topPanel );

        button1 = new JButton("One");

        button2 = new JButton("Many");

        String text = "Why shouldn't I work for the NSA? That's a tough one. But I'll take a\nshot. Say I'm working at the NSA, and somebody puts a code on my desk,\nsomethin' no one else can break. Maybe I take a shot at it and maybe I\nbreak it. And I'm real happy with myself, cus' I did my job well. But\nmaybe that code was the location of some rebel army in North Africa or\nthe Middle East and once they have that location, they bomb the\nvillage where the rebels are hiding... Fifteen hundred people that I\nnever met, never had no problem with get killed. Now the politicians\nare sayin', \"Oh, Send in the marines to secure the area\" cus' they\ndon't give a shit. It won't be their kid over there, gettin'\nshot. Just like it wasn't them when their number got called, cus' they\nwere pullin' a tour in the National Guard. It'll be some kid from\nSouthie over there takin' shrapnel in the ass. He comes back to find\nthat the plant he used to work at got exported to the country he just\ngot back from. And the guy who put the shrapnel in his ass got his old\njob, cus' he'll work for fifteen cents a day and no bathroom\nbreaks. Meanwhile he realizes the only reason he was over there in the\nfirst place was so that we could install a government that would sell\nus oil at a good price. And of course the oil companies used the\nlittle skirmish over there to scare up domestic oil prices. A cute\nlittle ancillary benefit for them but it ain't helping my buddy at\ntwo-fifty a gallon. They're takin' their sweet time bringin' the oil\nback, of course, maybe even took the liberty of hiring an alcoholic\nskipper who likes to drink martinis and fuckin' play slalom with the\nicebergs, it ain't too long 'til he hits one, spills the oil and kills\nall the sea life in the North Atlantic. So now my buddy's out of\nwork. He can't afford to drive, so he's walking to the fuckin' job\ninterviews, which sucks because the shrapnel in his ass is givin' him\nchronic hemorrhoids. And meanwhile he's starvin' cus' every time he\ntries to get a bite to eat the only blue plate special they're servin'\nis North Atlantic scrod with Quaker State. So what did I think? I'm\nholdin' out for somethin' better. I figure fuck it, while I'm at it\nwhy not just shoot my buddy, take his job, give it to his sworn enemy,\nhike up gas prices, bomb a village, club a baby seal, hit the hash\npipe and join the National Guard? I could be elected President.";

        JTextArea textArea = new JTextArea(text);
        scrollableTextArea = new JScrollPane(textArea);

        text1 = new JTextField("What a piece of work is man!", 100);
        text2 = new JTextField("How noble in reason! how infinite in faculties!");
        text3 = new JTextField("in form and moving, how express and admirable!");
        text4 = new JTextField("in action how like an angel!");
        text5 = new JTextField("in apprehension, how like a god!");
        text6 = new JTextField("the beauty of the world!");
        text7 = new JTextField("the paragon of animals!");
        text8 = new JTextField("And yet, to me, what is this quintessence of dust?");
        text9 = new JTextField("Man delights not me;");
        topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));

        // Note, DON'T use .pack() - or we undo all the
        // setSize/setLocation crap above.

    static public void main (String argv[]) {
        ActionExample actionExample = new ActionExample();