Learn Painters in LWUIT
The Painter interface
Painter portrays the fundamental interface for all articles that are expected to draw in establishments or to convey on a glass sheet. This interface articulates only a solitary system open void Painting Companies Chicago paint(Graphics g, Rectangle rect)- for drawing inside the hopping square shape (specifed by rect) of a section. The library gives a class that realizes Painter and is used as a default establishment painter for contraptions and holders. This is the BackgroundPainter class that has (you got it) basically the one procedure paint, which either paints the establishment picture if one has been consigned or fills in the ricocheting square state of the portion with the concealing set in its style.
Right when we have to paint an establishment ourselves, we can make our own class that executes Painter, and set it as the establishment painter for the appropriate section. The DemoPainter MIDlet, discussed in the accompanying portion, shows how this is done.
Add caption |
The DemoPainter application
This application makes a combo box and uses a subject to set the style for the various segments that are appeared. Right when the application is organized without setting a custom establishment painter, the combo limit looks as showed the going with screen catch:
The MIDlet code has the going with decree commented out in the MIDlet. When uncommented, this declaration sets a case of ComboBgPainter as the establishment painter for the combo box.
combobox.getStyle().setBgPainter(new ComboBgPainter(0x4b338c));
The class liable for drawing the establishment is ComboBgPainter, which executes Painter. The constructor for this class takes the concealing to be used for establishment painting as its solitary limit. The paint strategy chooses the headings of the upper left corner of the square shape to be painted and its estimations. The square shape is then flled using the concealing that was set through the constructor.
Drawing a multi-layered establishment
In certified practice, there isn't generally any point in using a custom painter just to paint an establishment concealing, because the setBgColor strategy for Style will generally complete the obligation. Themes additionally can be used for setting establishment shades. In any case, painters are incredibly useful when complex establishment plans ought to be drawn, and especially if various layers are incorporated. PainterChain, delineated in the accompanying zone, is a class planned for dealing with such essentials.
The PainterChain class
It is possible to use more than one painter to convey different layers of an establishment. Such a ton of painters can be affixed together through the PainterChain class. The principle constructor of this class has the structure open PainterChain(Painter[] chain) where the limit chain is an assortment of painters. The substance of chain will be called progressively during crafted by specialty of an establishment, starting from the part at record 0 to the last one.
There are two techniques for the PainterChain class that offer assistance for adding painters to the bunch central the chain. Another painter can be added either to the head (the prependPainter system) or around the end (the addPainter procedure) for the bunch. The bunch itself can be gotten to through the getChain methodology.
Comments
Post a Comment