Basic HTML version of Foils prepared 13 October 97

Foil 5 Graphics is Event-Driven: paint method

From Java Tutorial, July 1, 1996 CSC499(JSU) CPS406/606 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox


In every applet or windows application, the windowing system creates an Image with a Graphics object to keep track of the state of the window.
In order to draw or write text to the window, you must override the paint method:
  • public void paint(Graphics g)
The Graphics object g has a current color and font that can be changed by methods
The window system can be interrupted for various reasons - the user resized it or some other window was put on top of it and then removed - and it does not save a copy of the pixels. Instead it calls a method called update(), which blanks the screen and then calls paint(g). So even if you only draw one window, paint can be called many times.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998