import java.awt.*; // Java GUI classes import java.applet.*; import java.awt.event.*; // GUI Applet is loaded by GUI.html // Displays Labels, Fields, Button, TextArea // Constructs both BOOT and LOGIC public class GUI extends Applet implements ActionListener { private Logic logic; // GUI calls Logic for ACTIONS private TextField idField; // INPUT data private TextArea ta; // OUTPUT reports public void init() { super.init(); setLayout(null); // make a label Label idLabel = new Label("ID:"); idLabel.setBounds(20,10,50,30); add(idLabel); // make an INPUT field idField = new TextField(130); idField.setBounds(80,10,80,30); add(idField); // make a Create ACTION button Button createButton = new Button("Create"); createButton.setBounds(20,70,50,25); add(createButton); createButton.addActionListener(this); // make a List ACTION button Button listButton = new Button("List"); listButton.setBounds(80,70,50,25); add(listButton); listButton.addActionListener(this); // make a Test ACTION button Button testButton = new Button("Test"); testButton.setBounds(140,70,50,25); add(testButton); testButton.addActionListener(this); // make an OUTPUT textarea ta = new TextArea(); ta.setBounds(20,100,300,250); ta.setFont(new Font("Courier",Font.PLAIN,10)); add(ta); // pre-populate some initial beans Boot boot = new Boot(); // create Domain Logic, and give it the textarea for later printing logic = new Logic(ta); } // called by actionPerformed whenever a button is pushed // also called by StockTest to do Automated Test public void doAction(String arg) { // if Create is pushed, call logic's method to handle the ACTION // pass along the field, so logic can access the INPUT data if (arg.equals("Create")) { logic.createBean(idField); } // if List is pushed, call logic's method to handle the ACTION // logic already has textarea, so that it can always OUTPUT if (arg.equals("List")) { logic.listBeans(); } // if Test is pushed call GUITest to automatically fill in ID, // and to list all beans if (arg.equals("Test")) { new GUITest (this,ta,idField); } } // window manager calls this method when a button is pushed public void actionPerformed(ActionEvent event) { String arg = event.getActionCommand(); doAction(arg); } }