Time for action – creating a reusable widget
Although the ClockView
shows a single 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 pass them to the superclass:public ClockWidget(Composite parent, int style) { super(parent, style); }
- Move the implementation of the
drawClock
method from theClockView
to theClockWidget
. Remove thePaintListener
references from theClockView
class. - In the
ClockWidget
constructor, register aPaintListener
that delegates the call to thedrawClock
method:addPaintListener(this::drawClock); ...
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.