【发布时间】:2013-05-16 06:53:57
【问题描述】:
由于我找不到任何具体的地方来讨论这个,我想我会在这里发帖...... 我正在使用 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);
}
}
【问题讨论】:
-
你在什么地方被抓到了吗?您可以发布更具体的问题,例如错误吗?意外行为?
-
我的代码与教程中的代码非常相似。只是在最后更改了函数的声明以使其可以编译。听众似乎没有检测到点击。当我单击时,它应该在控制台上打印节点的 id,但没有任何反应......甚至没有例外。控制台保持干净。
-
愿意发布您的代码更改吗?
-
我只是将它们重新声明为“public void”,因为教程中的原版没有任何声明 - 只有功能名称存在。其余与教程相同
-
很抱歉我的回复太慢了。如果没有将代码示例粘贴到您的问题中,或者没有指向 Pastebin 之类的链接,则很难进行故障排除。您可能重新声明了构造函数或误读了他们发布的内容,这些内容应该只是对现有函数的一般性声明;在根据您提供的内容进行故障排除之前,该教程中有很多内容需要学习
标签: graph mouseevent java graphstream