SLG 20.2 CS 4 Java.awt.graphics
SLG 20.2 CS 4 Java.awt.graphics
TARGET
By the end of this learning guide module, the students should be able to:
1. Make a simple drawing application
HOOK
In the previous lesson, the java.awt.canvas was discussed wherein this component represents a
blank rectangular area of the screen onto which the application can draw or from which the application
can trap input events from the user.
In this module we will use the java.awt.Graphics. This class is is the abstract base class for all
graphics contexts that allow an application to draw onto components that are realized on various
devices, as well as onto off-screen images.
IGNITE
java.awt.Graphics
A Graphics object encapsulates state information needed for the basic rendering operations that Java
supports. This state information includes the following properties:
Coordinates are infinitely thin and lie between the pixels of the output device. Operations that draw the
outline of a figure operate by traversing an infinitely thin path between pixels with a pixel-sized pen
The graphics pen hangs down and to the right from the path it traverses. This has the following
implications:
If you draw a figure that covers a given rectangle, that figure occupies one extra row of
pixels on the right and bottom edges as compared to filling a figure that is bounded by that
same rectangle.
If you draw a horizontal line along the same y coordinate as the baseline of a line of text,
that line is drawn entirely below the text, except for any descenders.
All coordinates that appear as arguments to the methods of this Graphics object are considered relative
to the translation origin of this Graphics object prior to the invocation of the method.
All rendering operations modify only pixels which lie within the area bounded by the current clip, which
is specified by a Shape in user space and is controlled by the program using the Graphics object. This
user clip is transformed into device space and combined with the device clip, which is defined by the
visibility of windows and device extents. The combination of the user clip and device clip defines the
composite clip, which determines the final clipping region. The user clip cannot be modified by the
rendering system to reflect the resulting composite clip. The user clip can only be changed through the
setClip or clipRect methods. All drawing or writing is done in the current color, using the current paint
mode, and in the current font.
Example:
NAVIGATE
References
[1] Java.awt.graphics – JavaTpoint. (n.d.). Retrieved March 9, 2021, from
https://www.javatpoint.com/Java.awt.graphics
[2] Java.awt.graphics – Tutorialspoint. (n.d.). Retrieved March 9, 2021, from
https://www.tutorialspoint.com/java/Java.awt.graphics.htm
[3] Java.awt.graphics – java-examples (n.d.). Retrieved March 9, 2021, from
https://www.java-examples.com/Java.awt.graphics-examples
[3] Java.awt.graphics – docs.oracle (n.d.). Retrieved March 9, 2021, from
https://docs.oracle.com/javase/8/docs/api/java/lang/Java.awt.graphics.html