Off Screen GC

 

 

 

Foreword

Resources

Code Listings

Foil Sets

Assignments

Solutions

External Resources

SiteMap

Search

Home

Up ] Thread Base Applet ] Math Class ] String Classes ] [ Off Screen GC ] JavaApplet Context ] Events ] Networking ] Java Appl Design ]

The Off Screen Graphics Context

Some students ask me about an example on Off Screen GC and Scrolling String without blinking. The main idea about using an Off Screen GC is as follow:

  /* you create an image of the size you want inside applet. */
  Image img = createImage(w, h);
  /* Create an off screen GC associate with your image */
  Graphics offscr = img.getGraphics();
  /* using the off screen GC and drawing something on it */
  /* when you draw on GC, you actually draw on your image */
  offscr.setColor(Color.black);
  offscr.fillRect(0, 0, w, h);
  ....
  /* make sure your dispose the GC after you finish using it */
  offscr.dispose();

  /* after your image is prepared and ready, you draw your image
     on screen in paint or update method */

Example on Off Screen GC

The following is an example that use the off screen GC to show a scrolling sting upon stars background.

Source code : Scroll.java