由于我找不到任何具体的地方来讨论这个问题,所以我想我应该在这里发帖...... 我正在使用 graphstream 1.1 ( http://graphstream-project.org/ )(一个用于 java 的图形可视化库)来开发数据可视化工具。我需要检索节点上的鼠标点击来显示相关数据,但是在遵循库教程之后,我仍然不清楚如何执行此操作。使用过这个的人可以帮助我提供更直接的答案吗?我正在关注的教程位于:
public class Clicks implements ViewerListener {
protected boolean loop;
public static void main(String args[]) {
new Clicks();
}
public Clicks() {
// We do as usual to display a graph. This
// connect the graph outputs to the viewer.
// The viewer is a sink of the graph.
Graph graph = new SingleGraph("Clicks");
Viewer viewer = graph.display();
// The default action when closing the view is to quit
// the program.
viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.HIDE_ONLY);
// We connect back the viewer to the graph,
// the graph becomes a sink for the viewer.
// We also install us as a viewer listener to
// intercept the graphic events.
ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(this);
fromViewer.addSink(graph);
// Then we need a loop to wait for events.
// In this loop we will need to call the
// pump() method to copy back events that have
// already occured in the viewer thread inside
// our thread.
while(loop) {
fromViewer.pump();
}
}
viewClosed(String id) {
loop = false;
}
buttonPushed(String id) {
System.out.println("Button pushed on node "+id);
}
buttonReleased(String id) {
System.out.println("Button released on node "+id);
}
}
最佳答案
刚刚解决了!我向他们的邮件组发送了一封电子邮件。网站上的教程代码缺少一些信息。这三个函数需要是 public void,并且必须添加其他“导入”:
import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.swingViewer.ViewerListener;
import org.graphstream.ui.swingViewer.ViewerPipe;
关于graph - 在 Graphstream 中检索鼠标点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16671143/