//package howto; import java.applet.Applet; import java.awt.*; public class Main extends Applet { private Stack _s = null; private Panel _p = null; private TextField _tf = null; private Choice _ch = null; public void init() { setLayout(new BorderLayout()); _s = new Stack(); add("Center", _s); _p = new Panel(); _tf = new TextField(15); _p.add(_tf); _ch = new Choice(); _p.add(_ch); add("South", _p); } public boolean action(Event e, Object o) { if (e.target == _tf || e.target == _ch) { String str = (String)o; try { invoke(str); } catch (Exception exp) { panic(exp.toString()); } _s.display(); return true; } return false; } private void panic(String str) { System.out.println(str); } private void invoke(String str) throws Exception { Double d = null; try { d = new Double(str); } catch (NumberFormatException nfexp) { ; } if (d == null) { _ch.addItem(str); Class c = Class.forName("howto.operators." + str); Object o = c.newInstance(); Operator op = (Operator)o; op.operate(_s); } else { _s.push(d.doubleValue()); } } public Dimension preferredSize() { return new Dimension(300, 200); } public static void main(String [] args) { Frame f = new Frame("Main"); Main m = new Main(); m.init(); f.add("Center", m); f.pack(); f.show(); } }