Although the ClockView
shows an animated clock, creating an independent widget will allow the clock to be reused in other places.
Create a new class in the
com.packtpub.e4.clock.ui
package, calledClockWidget
, that extendsCanvas
.Create a constructor that takes a
Composite parent
and anint style
bits parameter, and passes them to the superclass:public ClockWidget(Composite parent, int style) { super(parent, style); }
Move the implementation of the
paintControl()
method from theClockView
to theClockWidget
. Remove thePaintListener
references from theClockView
class.In the
ClockWidget
constructor, register an anonymousPaintListener
that delegates the call to thepaintControl()
method:addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { ClockWidget.this.paintControl(e); } });
Move the
TickTock
thread fromClockView
to theClockWidget
constructor; this will allow theClockWidget
to operate independently. Change...