//      ExampleView is an example of how I like to subclass SCView. ExampleView
//      has the main method, and it would normally have an instance variable reffering
//      to the business model (primary object in your object model).
//      In initWidgets() a java.awt.TextArea is created and added to the widget table in
//      SCView with the String textArea1 as its key. Also, this object (the ExampleView
//      instance) is added to the KeyListener list of the TextArea. TextArea's generate
//      KeyEvents, so they keep track of their own KeyListeners who will all be
//      notified whenever a KeyEvent occurs by having the appropriate method in the
//      KeyListener interface called. (a KeyListener would be any object that
//      implements the KeyListener interface and is added as a KeyListener
//      to the object that generates the KeyEvent with the addKeyListener(KeyListener)
//      method, as is done in initWidgets()  ).  I hope this helps make your GUIs a
//      little more fun to write.


import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Menu;
import java.awt.TextArea;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;

class ExampleView extends SCView {

    private ExampleView(){
        super("Example View");
        this.initialize();
    }

    public static void main(String argv[]){

        ExampleView theExampleView = new ExampleView();
        theExampleView.show();

    }

    private void initialize(){

        this.setLayout(null);

        this.initMenu();
        this.initWidgets();

        this.setSize(300,300);
        this.setLocation(80,80);

    }
    private void initWidgets(){

        TextArea ta = new TextArea();
        ta.setSize(290,240);
        ta.setLocation(5,55);
        ta.addKeyListener(this);
        this.addWidget("textArea1", ta);

    }


    public void test(){
        System.out.println("test in ExampleView");
    }

   public void actionPerformed(ActionEvent e){
        String actionCommand = e.getActionCommand();
        if( actionCommand.equals("Exit") ){
            this.exit();
            return;
        }
        if( actionCommand.equals("Test") ){
            this.test();
            return;
        }
    }

    private void initMenu(){
        MenuBar aMenuBar = new MenuBar();
            Menu aMenu = new Menu("File");
                MenuItem aMenuItem = new MenuItem("Exit");
                aMenuItem.addActionListener(this);
                aMenuItem.setActionCommand("Exit");
            aMenu.add(aMenuItem);
            aMenuBar.add(aMenu);

            aMenu = new Menu("Test");
                aMenuItem = new MenuItem("Test");
                aMenuItem.addActionListener(this);
                aMenuItem.setActionCommand("Test");
            aMenu.add(aMenuItem);

            aMenuBar.add(aMenu);

        this.setMenuBar(aMenuBar);
    }
    public void windowClosing(WindowEvent we){
        this.exit();
    }
    private void exit(){
        System.out.println("closing ExampleView");
        try{ Thread.sleep(500); }
        catch(InterruptedException ie){}
        this.dispose();
        System.exit(0);
    }

    public void keyPressed(KeyEvent ke){
        System.out.println("keyPressed in ExampleView. keyText is " + ke.getKeyText(
                                                                        ke.getKeyCode()));
    }

}