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 mechanism called jobs
which would be just right for this task, but these will be covered in Chapter 4, Interacting with the User. So to begin with, a simple Thread
class will be used to issue the redraw.
Open the
ClockView
class.Add the following to the bottom of the
createPartControl()
method:new Thread("TickTock") { public void run() { while (!clock.isDisposed()) { clock.redraw(); try { Thread.sleep(1000); } catch (InterruptedException e) { return; } } } }.start();
Re-launch the test Eclipse instance and open the Clock View.
Open the host Eclipse instance and look in the Console View for the errors.