public class Editor extends JFrame { public Editor(Network network) { super("Editor"); JFrame.setDefaultLookAndFeelDecorated(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); NetworkPanel networkPanel = new NetworkPanel(network); add(networkPanel, BorderLayout.CENTER); MouseListener ml = new MouseAdapter() { Point[] points = new Point[2]; int index = 0; public void mouseClicked(MouseEvent arg0) { Point p = networkPanel.point(arg0.getPoint()); if (p != null) { points[index++] = p; if (index == 2) { network.addLink(points[0], points[1]); networkPanel.repaint(); index = 0; } } } }; networkPanel.addMouseListener(ml); setPreferredSize(new Dimension(400, 400)); pack(); setVisible(true); } // Exemple of use of the class Editor public static void main(final String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { int[] coords = { 50, 50, 100, 100, 100, 50, 200, 200, 300, 200, 200, 300}; Point[] points = new Point[coords.length / 2]; for (int i = 0; i < points.length; i++) { points[i] = new Point(coords[2 * i], coords[2 * i + 1]); } new Editor(new Network(points)); } }); } }