我将graphstream与我的swing应用程序一起使用,导致了很多问题......
public class Clicks implements ViewerListener{
protected boolean loop = true;
public Clicks() {
Graph graph = new SingleGraph("Clicks");
graph.addNode("A");
graph.addNode("ch");
graph.addNode("2");
Viewer viewer = graph.display();
viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);
ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(this);
fromViewer.addSink(graph);
while(loop) {
fromViewer.pump();
}
}
public void viewClosed(String id) {
loop = false;
}
public void buttonPushed(String id) {
System.out.println("Button pushed on node "+id);
}
public void buttonReleased(String id) {
System.out.println("Button released on node "+id);
}
}
上面给定的带有主站的类可以正常工作,但是当我从按钮单击事件中调用同一个类时,整个应用程序会停止……这是按钮代码
private void btnGraphStreamActionPerformed(java.awt.event.ActionEvent evt)
{
new Clicks();
}