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.

  1. Open the ClockView class.
  2. 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();
  3. Relaunch the test Eclipse instance, and open the Clock View.
  4. 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.