import java.beans.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.io.*; public class CreateUI { public static void main(String[] args) throws IOException { Factorize controller = new Factorize(); // Create the user interface JFrame f = new JFrame(); f.setTitle("Factorize"); Container p = f.getContentPane(); p.setLayout(null); f.setSize(new Dimension(400, 100)); JTextField t = new JTextField(); t.setBounds(10, 10, 100, 20); t.addActionListener((ActionListener)EventHandler.create(ActionListener.class, controller, "calculate", "source.text")); JLabel l = new JLabel(); l.setBounds(120, 10, 200, 20); JButton b = new JButton("Stop"); b.setBounds(300, 40, 70, 20); b.addActionListener((ActionListener)EventHandler.create(ActionListener.class, controller, "stop")); p.add(t); p.add(l); p.add(b); f.setVisible(true); // Create the XML document XMLEncoder e = new XMLEncoder( new BufferedOutputStream( new FileOutputStream("Factorize.xml"))); e.setOwner(controller); e.writeStatement(new Statement(controller, "loading", new Object[]{})); // Note: In 1.4 beta the object graph must be written before statments // are applied to the objects it creates. In 1.4 beta 2 this restriction // lifted and the following two statments can appear in either order. e.writeObject(f); e.writeStatement(new Statement(controller, "setOutput", new Object[]{l})); e.close(); System.exit(0); } }