Java Reference
In-Depth Information
green,andbluepercentages (between 0.0f and 1.0f ),andthelast argument repres-
ents opacity (from 0.0f , transparent, to 1.0f , opaque).
Afontistheninstalledtoensurethatthemessagebeingpaintedislargeenoughtobe
seen.
At this point, all that's left to do is obtain the message's width and height, and use
these values to determine the location of the first message character and the baseline,
and then draw the text.
After creating this decorator, it and the view (returned from createGUI() ) are
passed to a new JLayer instance, which is installed as the content pane.
Figure 7-14 shows the resulting GUI with the centered and translucent
UNREGISTERED message.
Figure 7-14. The UNREGISTERED message is centered within the frame window's bor-
ders.
SwingCanvas
AWTprovidesthe Canvas classwhose paint() methodcanbeoverriddentopaint
graphicsoranimageoveritssurface.YoucanintroduceyourownSwing-basedcanvas
class by subclassing JComponent and overriding its paint() method, as follows:
class SwingCanvas extends JComponent
{
private Dimension d;
SwingCanvas()
{
d = new Dimension(300, 300); // Create object here to
avoid unnecessary
//
object
creation
Search WWH ::




Custom Search