Troubleshooting

   

A Flicker-Free Drawing Surface

Whenever I try to change the font from inside a drawing surface's paint method, the contents of the drawing surface flicker. What's going on?

The problem originates from calling the wrong setFont method. Instead of calling setFont via the Graphics argument, you are calling the inherited setFont method from the Component class. When you call this method, a recursive loop is established and the drawing surface flickers. Here is a code fragment that demonstrates incorrectly and correctly setting the font:

 public void paint (Graphics g) 
   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net