Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto, 2002.

[Contents] [Next] [Previous]

Lab 3: Building Applets - Graphical representation


Modification of existing classes for graphical representation

How to provide graphical representation?

Graphical representation is actually very simple. An object should have access to the Graphics Instance in order to execute graphical commands.

The Graphics class 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. A Graphics object encapsulates state information needed for the basic rendering operations that Java supports. (Think like a canvas that every objects use to draw the representation of them selves on it. This canvas is passed among objects to let every object draw what the a coded for.)

The Coordinate System of each component has its own integer coordinate system, ranging from (0, 0) to (width - 1, height - 1), with each unit representing the size of one pixel. As the following figure shows, the upper left corner of a component's painting area is (0, 0). The X coordinate increases to the right, and the Y coordinate increases downward.

The Graphics class defines methods for painting the following kinds of shapes:

We will use these methods and define a method in each Mobile System Component to draw their corresponding shapes.


[Contents] [Next] [Previous]