Time for action – getting colorful

To add an option for the ClockWidget to have a different color, an instance must be obtained instead of the hardcoded BLUE reference. Since Color objects are Resource objects, they must be disposed correctly when the widget is disposed.

To avoid passing in a Color directly, the constructor will be changed to take an RGB value (which is three int values), and use that to instantiate a Color object to store for later. The lifetime of the Color instance can be tied to the lifetime of the ClockWidget.

  1. Add a private final Color field called color to the ClockWidget:
    private final Color color;
  2. Modify the constructor of the ClockWidget to take an RGB instance, and use it to instantiate a Color object. Note that the color ...

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.