Java graphics
Basic
principles
Graphics methods are part of the AWT. Important AWT
graphics classes include:
Because a Java program may be sharing the computer screen
with any number of other programs, graphics methods are directed to specific AWT
components. There is not, nor should there ever be, any procedure to draw directly to the
screen. This means that when specifying the position of a shape or image, we specify it
relative to the component in which it is drawn.
Although it is possible to draw graphics directly to a
Window or Frame object, this is a bad practice. Doing this makes it difficult to re-use
the graphics code in new programs (because one would have to separate out the graphics
parts from the part that handles window events). The correct procedure is to create a
subclass of Canvas or Panel and make it draw itself by over-riding the ‘paint’
method.
In Java, as in most programming languages that support a
graphical user interface, the graphics methods are volatile (you will also see the term
`non-persistent' used). This means that the graphical information that is displayed on the
screen will not be retained if the program's display is over-written. This happens if, for
example, your program is hidden `behind' another program on the screen. When this happens,
your program must be ready to re-draw its display whenever it is `raised' to the top
again.
Java makes this quite straightforward. Every
user interface component has a method called paint(). This method is called
whenever the system detects that the component needs to be re-painted. It is not the job
of the programmer to manage the re-painting of the screen.
Back
to top

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg
|