The Painter interface
Painter defines the elemental interface for all objects that are meant to attract backgrounds or to render over a glass pane. This interface declares just one approach-public void paint(Graphics g, Rectangle rect)-for drawing In the bounding rectangle (specifed by rect) of the element. The library supplies a class that implements Painter and is also utilized as being a default history painter for widgets and containers. Here is the BackgroundPainter course that has (you guessed it) just the a single system paint, which possibly paints the track record image if one has become assigned or fills MONTCLAIR PAINTING VIP from the bounding rectangle in the ingredient with the colour set in its fashion.
When we want to paint a track record ourselves, we are able to write our very own course that implements Painter, and set it given that the track record painter to the relevant part. The DemoPainter MIDlet, reviewed in the next area, reveals how This is certainly completed.
The DemoPainter application
This application results in a combo box and works by using a theme to set the design and style for the varied factors that happen to be shown. When the appliance is compiled without setting a custom qualifications painter, the combo box looks as revealed in the following screenshot:
The MIDlet code has the following assertion commented out from the MIDlet. When uncommented, this assertion sets an instance of ComboBgPainter as the track record painter for that combo box.
combobox.getStyle().setBgPainter(new ComboBgPainter(0x4b338c));
The category accountable for drawing the qualifications is ComboBgPainter, which implements Painter. The constructor for this course can take the color for use for history painting as its only parameter. The paint strategy determines the coordinates of the best-still left corner with the rectangle to generally be painted and its dimensions. The rectangle is then flled making use of the colour which was set with the constructor.