Time for action – animating the second hand
The second hand is drawn with a redraw
on the Canvas
, but this will need to be run periodically. If it is redrawn once per second, it can emulate a clock ticking.
Eclipse has a jobs
plug-in, which would be just right for this task, but this will be covered in Chapter 4, Interacting with the User. So to begin with, a simple Thread
will be used to issue the redraw.
- Open the
ClockView
class. - Add the following at the bottom of the
createPartControl
method:Runnable redraw = () -> { while (!clock.isDisposed()) { clock.redraw(); try { Thread.sleep(1000); } catch (InterruptedException e) { return; } } }; new Thread(redraw, "TickTock").start();
- Relaunch the test Eclipse instance, and open the Clock View.
- Open the ...
Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.