package com.mindprod.example;

import com.mindprod.common11.FontFactory;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * demonstrate the use of java.awt.TextArea
 * <p/>
 * composed with IntelliJ IDEA
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0
 */
public final class TestTextArea
    {
    // --------------------------- main() method ---------------------------

    /**
     * Debugging harness for a Frame
     *
     * @param args not used.
     */
    public static void main( String args[] )
        {
        final Frame frame = new Frame();

        // The user hitting enter inserts a \n character into the text.
        final TextArea textarea = new TextArea( "this is a TEST" );
        textarea.setBackground( Color.BLACK );
        textarea.setForeground( Color.YELLOW );
        textarea.setFont( FontFactory.build( "Dialog", Font.BOLD, 15 ) );
        textarea.setEnabled( true );
        textarea.setEditable( true );
        textarea.addTextListener( new TextListener()
        {
        /**
         * Invoked when the value of the text has changed. The code written
         * for this method performs the operations that need to occur when
         * text changes.
         */
        public void textValueChanged( TextEvent e )
            {
            System.out.println( textarea.getText() );
            }
        } );

        frame.add( textarea );

        frame.setSize( 100, 100 );
        frame.addWindowListener( new WindowAdapter()
        {
        /**
         * Handle request to shutdown.
         *
         * @param e event giving details of closing.
         */
        public void windowClosing( WindowEvent e )
            {
            System.exit( 0 );
            }// end WindowClosing
        }// end anonymous class
        );// end addWindowListener line
        frame.validate();
        frame.setVisible( true );
        }// end main
    }