/**
 * Program Runner
 *   - code that creats a Parkland Student
 *     Program and then runs it.
 * 
 * Always include this file in your projects
 *   but you should not have to change any  
 *   code in this file.
 *
 *
 * @Scott Badman 
 * @Parkland College, Csc 123, Fall 2006
 */
 
import java.awt.*;
import java.awt.event.*;
public class ProgramRunner extends Frame implements ActionListener
{
    
	private ParklandStudentProgram program = new ParklandStudentProgram();
	private	Label prompt;
	private	TextField input1, input2, input3;
    private	TextArea result;
    /**
     * The constructor.
     */ 
     public ProgramRunner()
     {
        MenuBar menuBar = new MenuBar();
        Menu menuFile = new Menu();
        MenuItem menuFileExit = new MenuItem();
        
        menuFile.setLabel("File");
        menuFileExit.setLabel("Exit");
        
        // Add action listener.for the menu button
        menuFileExit.addActionListener
        (
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            }
        ); 
        menuFile.add(menuFileExit);
        menuBar.add(menuFile);
        
        setMenuBar(menuBar);
        setSize(new Dimension(400, 400));
        
        // Add window listener.
        this.addWindowListener
        (
            new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            }
        );  
		this.setLayout(new FlowLayout());
		this.setSize(400, 250);
		
		prompt = new Label();
		add(prompt);
		
        input1 = new TextField(6);
        input1.addActionListener(this);
        add(input1);
        input2 = new TextField(6);
        input2.addActionListener(this);
        add(input2);
        input3 = new TextField(6);
        input3.addActionListener(this);
        add(input3);
    	result = new TextArea(7, 40);
    	add(result);
    }
    
    public void actionPerformed(ActionEvent e) 
    {
		program.respond(this, input1, input2, input3, result);
		validate();
    }
      
    public void run()
    {
  		program = new ParklandStudentProgram();	
    	program.prepare(this, prompt);
    	validate();	
    }
    
    public static void main(String[] args) {
        // Create application frame.
        ProgramRunner frame = new ProgramRunner();
        
        // Show frame
        frame.setVisible(true);
        
        // tell the frame to run the student's program
        frame.run();
    }
}