I am using a scheduledexecutorservice to perform an animation for drawing a graph(one vertex and one edge at a time). I have a problem in updating the actual UI step by step and instead I can't see the actual animation but only the final graph.
private Runnable newRunnable() {
return new Runnable() {
@Override
public void run() {
// this method just adds the graph to a JPanel
displayDiagram();
}
};
}
private void animate() {
executorService.schedule(newRunnable(), 1500, TimeUnit.MILLISECONDS);
executorService.shutdown();
try {
executorService.awaitTermination(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
executorService = new ScheduledThreadPoolExecutor(1);
}
What I want to achieve is to be able to draw one vertex and one edge, and update the UI every time and then wait for 1500ms and do that again until the whole graph is displayed.
Method animate would be called multiple times as the graph is dynamically being created.