//********************************************************************************
// Applet template - put your name, date,and program name here
// Note that this program can be run as either an applet or an application
//*********************************************************************************

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class MyApplet extends Applet
{
    // declare major variables here - Use meaningful names!!
    static final int WINDOW_WIDTH = 600;
    static final int WINDOW_HEIGHT = 400;
   
    // input text box - this makes a one line box where the user can put in data.  You probably will need several
    TextField inputField = new TextField (10);
    // output text box - this is a multi-line box where you can display messages.  You could have more than 1
    TextArea outputText = new TextArea(10,40);
    // buttons - to make other kinds of buttons, declare them here and name them something other than print
    Button printButton = new Button (" Print ");

    //***************************************************************************
    // init
    //
    // This code is run when an applet is started but before it is made visible.  It is not executed when
    // the program is run as an application.
    //***************************************************************************
    public void init()
    {
        add(new Label(" puts words in applet "));
        add(printButton);
        add(outputText);
        printButton.addActionListener(new PrintListener());

        outputText.append("Ready when you are. \n");
    }

    //***************************************************************************
    // main
    //
    // This code is run when the program is run as an application.  Note that it is not executed when the
    // program is run as an applet unless you call it directly.  You should not have to change this code.
    // Note that it calls init to make the window look and work the same as an applet.
    //***************************************************************************
    public static void main(String[] args)
    {
        MyApplet application;

        Frame myWindow = new Frame("Name of the application");
        application = new MyApplet();
        application.init();
        myWindow.add(application);
        myWindow.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

        // Code to handle closing a window
        myWindow.addWindowListener(
            new WindowAdapter()
            {
                public void windowClosing( WindowEvent event)
                {
                    System.exit(0);
                }
            }
        ); // end of call to addWindowListener

        myWindow.setVisible(true);
    }

    //***************************************************************************
    // PrintListener
    //
    // You will probably want to have one ActionListener for each button.  Note that this one just puts
    // some text in the output field.  You will probably also do calculations here.
    //***************************************************************************
    class PrintListener implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            try
            {
                String input;
                outputText.setText("You know how to push my button");
                input = inputField.getText();
                outputText.append(input);
            }
            catch (NumberFormatException e2)
            {
            }
        } // end actionPerformed
    } // end PrintListener
} // end myapplet