我正在尝试使用GraphStream API创建图表。我想在使用API绘制的图形布局顶部添加一些视觉效果,因此我计划将图形嵌入到JFrame中。
我在这里阅读这篇文章(How to draw graph inside swing with GraphStream actually?),看一些实现,但我总是收到异常错误:
Exception in thread "AWT-EventQueue-0" java.lang.VerifyError: (class: org/graphstream/ui/swingViewer/Viewer, method: addDefaultView signature: (Z)Lorg/graphstream/ui/swingViewer/View;) Incompatible argument to function
at ShowGraph$MyFrame.<init>(ShowGraph.java:17)
at ShowGraph$1.run(ShowGraph.java:34)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
使用的代码与链接中的代码相同:
public class ShowGraph
{
private static Graph graph = new SingleGraph("Graph");
public static class MyFrame extends JFrame
{
private static final long serialversionUID = 8394236698316485656L;
private Viewer viewer = new Viewer(graph,Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
private View view = viewer.addDefaultView(false);
public MyFrame()
{
setLayout(new BorderLayout());
add(view,BorderLayout.CENTER);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
public static void main(String args[])
{
SwingUtilities.invokeLater(new Runnable()
{
public void run() {
graph.addNode("A");
graph.addNode("B");
graph.addNode("C");
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CA", "C", "A");
MyFrame frame = new MyFrame();
frame.setSize(320, 240);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}