/** * Set up the applet's GUI. * As recommended, the init method executes this in the event-dispatching * thread. */ public void run() { Container pane = getContentPane(); pane.setLayout(new BorderLayout()); // Build the button controls JRadioButton voronoiButton = new JRadioButton("Voronoi Diagram"); voronoiButton.setActionCommand("voronoi"); JRadioButton delaunayButton = new JRadioButton("Delaunay Triangulation"); delaunayButton.setActionCommand("delaunay"); JButton clearButton = new JButton("Clear"); clearButton.setActionCommand("clear"); ButtonGroup group = new ButtonGroup(); group.add(voronoiButton); group.add(delaunayButton); JPanel buttonPanel = new JPanel(); buttonPanel.add(voronoiButton); buttonPanel.add(delaunayButton); buttonPanel.add(clearButton); pane.add(buttonPanel, "North"); // Build the mouse-entry switches JLabel circleLabel = new JLabel("Show Empty Circles"); circleLabel.setName("circles"); JLabel delaunayLabel = new JLabel("Show Delaunay Edges"); delaunayLabel.setName("delaunay"); JLabel voronoiLabel = new JLabel("Show Voronoi Edges"); voronoiLabel.setName("voronoi"); JPanel switchPanel = new JPanel(); switchPanel.add(circleLabel); switchPanel.add(new Label(" ")); switchPanel.add(delaunayLabel); switchPanel.add(new Label(" ")); switchPanel.add(voronoiLabel); pane.add(switchPanel, "South"); // Build the graphics panel DelaunayPanel graphicsPanel = new DelaunayPanel(); graphicsPanel.setBackground(Color.gray); pane.add(graphicsPanel, "Center"); // Register the listeners voronoiButton.addActionListener(graphicsPanel); delaunayButton.addActionListener(graphicsPanel); clearButton.addActionListener(graphicsPanel); graphicsPanel.addMouseListener(graphicsPanel); circleLabel.addMouseListener(graphicsPanel); delaunayLabel.addMouseListener(graphicsPanel); voronoiLabel.addMouseListener(graphicsPanel); // Initialize the radio buttons voronoiButton.doClick(); }
/** * Set up the applet's GUI. * As recommended, the init method executes this in the event-dispatching * thread. */ public void run() { Container pane = getContentPane(); pane.setLayout(new BorderLayout()); // Build the button controls JRadioButton voronoiButton = new JRadioButton("Voronoi Diagram"); voronoiButton.setActionCommand("voronoi"); JRadioButton delaunayButton = new JRadioButton("Delaunay Triangulation"); delaunayButton.setActionCommand("delaunay"); JButton clearButton = new JButton("Clear"); clearButton.setActionCommand("clear"); ButtonGroup group = new ButtonGroup(); group.add(voronoiButton); group.add(delaunayButton); JPanel buttonPanel = new JPanel(); buttonPanel.add(voronoiButton); buttonPanel.add(delaunayButton); buttonPanel.add(clearButton); pane.add(buttonPanel, "North"); // Build the mouse-entry switches JLabel circleLabel = new JLabel("Show Empty Circles"); circleLabel.setName("circles"); JLabel delaunayLabel = new JLabel("Show Delaunay Edges"); delaunayLabel.setName("delaunay"); JLabel voronoiLabel = new JLabel("Show Voronoi Edges"); voronoiLabel.setName("voronoi"); JPanel switchPanel = new JPanel(); switchPanel.add(circleLabel); switchPanel.add(new Label(" ")); switchPanel.add(delaunayLabel); switchPanel.add(new Label(" ")); switchPanel.add(voronoiLabel); pane.add(switchPanel, "South"); // Build the graphics panel DelaunayPanel graphicsPanel = new DelaunayPanel(); graphicsPanel.setBackground(Color.gray); pane.add(graphicsPanel, "Center"); // Register the listeners voronoiButton.addActionListener(graphicsPanel); delaunayButton.addActionListener(graphicsPanel); clearButton.addActionListener(graphicsPanel); graphicsPanel.addMouseListener(graphicsPanel); circleLabel.addMouseListener(graphicsPanel); delaunayLabel.addMouseListener(graphicsPanel); voronoiLabel.addMouseListener(graphicsPanel); // Initialize the radio buttons voronoiButton.doClick(); }