import java.awt.*; import java.awt.event.*; /** * The graphical aspect of this application. * * @author Marcel Turcotte */ public class Viewer extends Frame implements ActionListener { private Interpreter lvm; // Luka Virtual Machine private Display display; private Button bExecute = new Button( "Execute" ); private TextArea input = new TextArea(); /** * Creates the visual display of the application. Creates a * PostScriptDisplay, Button and TextArea. * * @param lvm a reference to an interpreter. */ public Viewer( Interpreter lvm ) { super( "DrLuka" ); this.lvm = lvm; setBackground( Color.WHITE ); display = new Display( this ); display.setSize( 400,400 ); display.setBackground( Color.WHITE ); add( display,BorderLayout.CENTER ); bExecute.addActionListener( this ); Panel control = new Panel(); control.setLayout( new FlowLayout() ); control.add( bExecute ); Panel console = new Panel(); console.setLayout( new BorderLayout() ); input.setBackground( Color.WHITE ); console.add( input, BorderLayout.CENTER ); console.add( control, BorderLayout.SOUTH ); add( console, BorderLayout.SOUTH ); /** * Calls display.repaint(), which in turns calls the method * paint of the component with a reference to the Graphics * object. Finally, the method paint calls our own method */ addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } }); pack(); setVisible( true ); } public void actionPerformed( ActionEvent e ) { display.repaint(); } public void paint( Graphics g ) { String program = input.getText(); lvm.execute( program, g ); } }