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

public class TextAreaFrame extends JFrame
{
    private static int WIDTH = 550;
    private static int HEIGHT = 260;

    private int row = 10;
    private int col = 20;

         //GUI components
    private JTextField lineTF;
    private JTextArea whiteBoardTA;
    private JButton exitB, appendB;

    private ButtonEventHandler eventHandler;

    public TextAreaFrame()
    {
        setTitle("White Board");
        setSize(WIDTH, HEIGHT);

        Container pane  = getContentPane();

          //instantiate the GUI components
        lineTF = new JTextField(20);
        whiteBoardTA = new JTextArea(row, col);
        exitB = new JButton("Exit");
        appendB = new JButton("Append");

          //Create event handler
        eventHandler = new ButtonEventHandler();

          //register the action listener with the buttons
        exitB.addActionListener(eventHandler);
        appendB.addActionListener(eventHandler);

          //set the layout of the pane to null
        pane.setLayout(null);

           //set the locations of the GUI components
        lineTF.setLocation(20, 50);
        whiteBoardTA.setLocation(320, 10);
        appendB.setLocation(230, 50);
        exitB.setLocation(20, 140);

          //set the sizes of the GUI components
        lineTF.setSize(200, 30);
        whiteBoardTA.setSize(200, 200);
        appendB.setSize(80, 30);
        exitB.setSize(200, 30);

          //add components to the pane
        pane.add(lineTF);
        pane.add(whiteBoardTA);
        pane.add(appendB);
        pane.add(exitB);
     //   pane.add( new JScrollPane( whiteBoardTA ) );
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    } //end of the constructor

    private class ButtonEventHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            if (e.getActionCommand().equals("Append"))
               whiteBoardTA.append((lineTF.getText() + "\n"));
            else if (e.getActionCommand().equals("Exit"))
                System.exit(0);
        }
	}

    public static void main(String[] args)
    {
    	TextAreaFrame board = new TextAreaFrame();
    }

}
