- From: Stephen Andrasi <andristv94 AT gmail.com>
- To: graphstream-users AT litislab.fr
- Subject: Graph animation problem
- Date: Sat, 11 Mar 2017 21:24:27 +0100 (CET)
Hi, my name is Stephen.
I'm working on a project where my task is to make a graph algorithm
visualizer.
I have a Jbutton at the bottom of the window and above it there is the graph.
I have an "Animate" button to start the algorithm on the graph, but it does
not
work.
I want to draw the edges step by step. (I added a little pause)
What am I doing wrong? :(
public class EZ{
private static Graph graph = new SingleGraph("Graph");
public static class MyFrame extends JFrame
{
private Viewer viewer = new
Viewer(graph,Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
private View view = viewer.addDefaultView(false);
private JButton button = new JButton("ASD");
public ViewerPipe pipe = viewer.newViewerPipe();
public MyFrame()
{
graph.addAttribute("ui.stylesheet", "url('src/style/graph.css')");
viewer.enableAutoLayout();
setLayout(new BorderLayout());
add((Component) view,BorderLayout.CENTER);
add(button, BorderLayout.AFTER_LAST_LINE);
setDefaultCloseOperation(EXIT_ON_CLOSE);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
graph.getNode("A").setAttribute("ui.class",
"walking");
pipe.pump();
long start = new Date().getTime(); // small pause
while(new Date().getTime() - start < 1000L){}
graph.getNode("A").setAttribute("ui.class",
"walking");
pipe.pump();
}
});
}
}
public static void main(String args[])
{
SwingUtilities.invokeLater(new Runnable()
{
public void run() {
graph.addNode("A").setAttribute("ui.label", "A");
graph.addNode("B").setAttribute("ui.label", "B");
graph.addNode("C").setAttribute("ui.label", "C");
graph.addEdge("AB", "A", "B").setAttribute("ui.label", "1");
graph.addEdge("BC", "B", "C").setAttribute("ui.label", "6");
graph.addEdge("CA", "C", "A").setAttribute("ui.label", "2");
MyFrame frame = new MyFrame();
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
Greetings,
Stephen
- Graph animation problem, Stephen Andrasi, 11/03/2017
Archives gérées par MHonArc 2.6.16.