1 package com.mxgraph.examples.swing;
2 
3 import java.awt.event.MouseAdapter;
4 import java.awt.event.MouseEvent;
5 
6 import javax.swing.JFrame;
7 
8 import com.mxgraph.swing.mxGraphComponent;
9 import com.mxgraph.view.mxGraph;
10 
11 public class ClickHandler extends JFrame
12 {
13 
14 	/**
15 	 *
16 	 */
17 	private static final long serialVersionUID = -2764911804288120883L;
18 
ClickHandler()19 	public ClickHandler()
20 	{
21 		super("Hello, World!");
22 
23 		final mxGraph graph = new mxGraph();
24 		Object parent = graph.getDefaultParent();
25 
26 		graph.getModel().beginUpdate();
27 		try
28 		{
29 		   Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
30 		         30);
31 		   Object v2 = graph.insertVertex(parent, null, "World!",
32 		         240, 150, 80, 30);
33 		   graph.insertEdge(parent, null, "Edge", v1, v2);
34 		}
35 		finally
36 		{
37 		   graph.getModel().endUpdate();
38 		}
39 
40 		final mxGraphComponent graphComponent = new mxGraphComponent(graph);
41 		getContentPane().add(graphComponent);
42 
43 		graphComponent.getGraphControl().addMouseListener(new MouseAdapter()
44 		{
45 
46 			public void mouseReleased(MouseEvent e)
47 			{
48 				Object cell = graphComponent.getCellAt(e.getX(), e.getY());
49 
50 				if (cell != null)
51 				{
52 					System.out.println("cell="+graph.getLabel(cell));
53 				}
54 			}
55 		});
56 	}
57 
main(String[] args)58 	public static void main(String[] args)
59 	{
60 		ClickHandler frame = new ClickHandler();
61 		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
62 		frame.setSize(400, 320);
63 		frame.setVisible(true);
64 	}
65 
66 }
67