// File:  JTextFieldDemo\JTextFieldDemo.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JTextFieldDemo extends JFrame {

    public JTextFieldDemo() {
        // Set application title
        super("JTextFieldDemo");

        // Register the Listener and the Handler
        clearButton.addActionListener(new ClearListener());

        // Set up for one or more buttons at the top of the application
        JPanel p = new JPanel(new FlowLayout());
        p.add(clearButton);

        // Set up the BorderLayout so that it looks "pretty"
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        c.add(BorderLayout.NORTH, p);
        c.add(BorderLayout.CENTER, textArea);
        c.add(BorderLayout.WEST, new JLabel("  "));
        c.add(BorderLayout.EAST, new JLabel("  "));
        c.add(BorderLayout.SOUTH, bottomLabel);
        // Set up the vertical scroll bar
        c.add(new JScrollPane(textArea));

        // Initialize and load the JTextArea
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        String s = "";
        for (char ch = 'a'; ch <= 'z'; ch++)
            s = s + ch + ch + " ";
        s = "Type text into this field...\n\n" + "11 " + s + "\n\n22 " + s;
        textArea.setText(s);
    }

    // Handler for the Clear button
    class ClearListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            bottomLabel.setText("  Clear");
            textArea.setText("");
        }
    }

    public static void main(String[] args) {
        JTextFieldDemo f = new JTextFieldDemo();
        f.setSize(WIDTH, HEIGHT);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.setVisible(true);
    }

    private JTextArea textArea  = new JTextArea();
    private JButton clearButton = new JButton("Clear");
    private JLabel bottomLabel  = new JLabel("  Press Clear...");

    private static final int WIDTH  = 125;
    private static final int HEIGHT = 175;
}
