Java Reference
In-Depth Information
• Iuseapairofnestedloopstodrawlines.Youshouldavoidusinglengthyloops
inthe paint() methodbecausetheycanmaketheuserinterfacelessperform-
ant. Shorter loops are not a problem.
• I center the bottom string horizontally by subtracting the total advance width
(returned from stringWidth() ) from the canvas's width and dividing the
result by 2. I center the string's baseline vertically by dividing the canvas's
height by 2.
• Iachieveadrop-shadoweffectbyfirstdrawingthebottomstringinyellow(the
shadow color) and then drawing the same string in red, but offset three pixels
horizontally and three pixels vertically.
Figure7-9 presentsthenoninvertedcanvaswithredonyellowtext,agreenoval,and
a blue rectangle.
Figure 7-9. A canvas can be used to paint an application's splash screen.
so.Forexample, Component alsodeclaresa void update(Graphics g) meth-
od for updating a heavyweight component in response to a repaint() method call.
You can learn about this method and more by reading “Painting in AWT and Swing”
Search WWH ::

Custom Search