GCanvas class, which is a lightweight
container that supports the addition of graphical objects that correspond to the
shapes attached to the board. These graphical objects come from a variety of
classes that represent geometrical shapes and other graphical entities including
lines, ovals, rectangles, images, and strings.
The standard approach to using the acm.graphics package consists
of the following steps:
GCanvas object to serve as the surface to which
subsequent graphical objects are attached.
JFrame
object and then add the GCanvas at the center of that frame.
add method in GCanvas to add new graphical
objects from the GObject hierarchy.
As an example, the following main program follows this outline to display a red square on the screen:
|
Much of this boilerplate can be eliminated by using the
GraphicsProgram class
in the acm.program package.
The public classes in the acm.graphics package can be diagrammed
as follows:
![]() |