// retire // The UI class for the applet/application incarnation of the retire client // import com.compaq.servit.*; import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class retire extends Applet implements ActionListener, WindowListener { static retire planner; // Primarily handler for window events // Top-level UI components static Frame fr; static Button crButton, gpButton; static CalcRetBox crBox; static Dialog gpBox; static MsgBox msgBox; // Process click on button. Listener for action events public void actionPerformed(ActionEvent ae) { Object obj = ae.getSource(); if (obj == crButton) crBox.show(); else if (obj == gpButton) gpBox.show(); else return; // Didnt handle action } static Frame getParentFrame(Component comp) { // Dboxes are children of nearest encompassing frame while ((comp=comp.getParent()) != null) { if (comp instanceof Frame) break; } return (Frame)comp; } // Build work object and UI components for app or applet public void init() { // Init frame for UI // Fields are arranged in 6 x 4 grid. Insure use bold font fr = getParentFrame(this); fr.addWindowListener(this); fr.setSize(300, 60); fr.show(); // Create "menu system" setLayout(new FlowLayout()); add(crButton = new Button("Calculate Retirement Data")); add(gpButton = new Button("Get Portfolio")); validate(); // Factories need to exist to create server conns Servit.setClientContext(this, "inprocess://:2000"); String debstr = Servit.getProperty("debug"); try { if (debstr!=null) Servit.setDebugOptions(Integer.parseInt(debstr)); } catch (Exception e) {} Util.factoryCalcRet = new Servit("CalcRet", null); Util.factoryBroker = new Servit("Broker", null); // Create dboxes and their server connections. crBox = new CalcRetBox(fr, "Calculate Retirement Data", false); gpBox = new GetPortBox(fr, "Get Portfolio", false); msgBox = new MsgBox(fr, null, true); // Now that everything exists, activate "menu items" crButton.addActionListener(this); gpButton.addActionListener(this); } // End init() // Initiate applic ui public static void main(String args[]) { Frame f = new Frame("Retirement Planner"); planner = new retire(); f.add("Center", planner); planner.init(); planner.start(); } // Listen for window events public void windowActivated(WindowEvent we) { } public void windowClosed(WindowEvent we) { } public void windowClosing(WindowEvent we) { if (we.getWindow()==fr) { fr.dispose(); System.exit(0); } else we.getWindow().setVisible(false); } public void windowDeactivated(WindowEvent we) { } public void windowDeiconified(WindowEvent we) { } public void windowIconified(WindowEvent we) { } public void windowOpened(WindowEvent we) { } }