import java.awt.*;
import java.awt.event.*;
public class GraphicsDriver 
{
	public static void main( String []args)
	  {
	  	  new GraphicsTest(); // implements an automatic object
	  	 
      }
}
class GraphicsTest extends Frame implements KeyListener,WindowListener  
                            // Can be in the same file
							//because public is missing
{    
    Button first = new Button("First");
    Button second = new Button("Second");
    public GraphicsTest()                //constructor  executes on implementation
    {
    	setTitle("First program");
    	addKeyListener(this);    //activates KeyListener
        addWindowListener(this); //activates WindowListener
        setLayout(new FlowLayout(FlowLayout.LEFT));
        add(first);   // add buttons to Frame
        add(second);
        setSize(600,400);  //Sets the size of the frame in pixels
    	setVisible(true);
    	//while(true);   // infinite loop - The operating system interrupts when
				// a key is activated
    }
    public void paint(Graphics pen)
    {
    	pen.fillRect(100,100,200,50);
    }	
    public void windowClosing(WindowEvent w)//ALL abstract methods in WindowListener
    {										//interface must be overridden
    	System.exit(0);   //Closes program
    }
    public void windowOpened(WindowEvent w)
    {
    	
    }
    public void windowClosed(WindowEvent w)
    {
    	System.exit(0);    //Closes program
    }
    public void windowDeactivated(WindowEvent w)
    {
    	System.exit(0);    //Closes program
    }
    public void windowDeiconified(WindowEvent w)
    {
    	
    }
    public void windowIconified(WindowEvent w)
    {
    	
    }
    public void windowActivated(WindowEvent w)
    {
    	
    }
    public void keyTyped(KeyEvent e)  //overridden methods
    {
    	this.setTitle("" +e.getKeyChar());
    	System.out.println("TYPED "+e.getKeyChar());
    } 
	public void keyPressed(KeyEvent e)
    {
    	this.setTitle("" +(char)e.getKeyCode());
    	System.out.println("PRESSED "+(char)e.getKeyCode());
    } 
	public void keyReleased(KeyEvent e)
    {
    	System.out.println("RELEASED "+e.getKeyCode());
    } 
   
}

