1:/* 2: * Programming graphicxal user interfaces 3: * Example: DiagramApp 4: * Jarkko Leponiemi 2002 5: */ 6: 7:import javax.swing.*; 8:import java.awt.event.*; 9: 10:/** 11: * The diagram application main window. Includes the entry point 12: * of the application. 13: */ 14:public class DiagramApp extends JFrame 15:{ 16: public DiagramApp(String title) { 17: super(title); 18: Diagram d = createInitialDiagram(); 19: DiagramView dv = new DiagramView(d); 20: getContentPane().add(dv); 21: } 22: 23: // create an initial diagram 24: private Diagram createInitialDiagram() { 25: Diagram d = new Diagram(); 26: Diagram.Node n1 = d.createNode("Yksi", 50, 50); 27: Diagram.Node n2 = d.createNode("Kaksi", 100, 100); 28: d.createConnector(n1, n2); 29: Diagram.Node n3 = d.createNode("Kolme", 150, 50); 30: d.createConnector(n1, n3); 31: d.createConnector(n2, n3); 32: Diagram.Node n4 = d.createNode("Neljä", 200, 100); 33: d.createConnector(n3, n4); 34: return d; 35: } 36: 37: public static void main(String[] args) { 38: JFrame f = new DiagramApp("Diagram"); 39: f.addWindowListener(new Exiter()); 40: f.setBounds(100, 100, 300, 200); 41: f.show(); 42: } 43: 44: // an inner class for exiting the application 45: private static class Exiter extends WindowAdapter 46: { 47: public void windowClosing(WindowEvent e) { 48: System.exit(0); 49: } 50: } 51:}