Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto,
2002.
Lab 3: Building Applets - Graphical representation
By now, you should already have a BlueJ presentation similar to the following
figure.
If you have not, please click on the Class that is not exists or you suspect
to be different to revisit the corresponding discussion of its declaration.
Please open editor on the CircleCell to modify it.
In order to indicate that CircleCell implements Visualization interface, the
Class declaration should change into:
public class CircleCell extends Cell implements Visualization
Then add a new method called draw(Graphics g) inside the Class definition.
We will use the drawOval(int x,int y,int width,int height) method.
It will draw the outline of an oval in the Graphics context. The result is a
circle or ellipse that fits within the rectangle specified by the x, y, width,
and height arguments.
The oval covers an area that is width + 1 pixels wide and height + 1 pixels
tall.
The complete implementation in Java is shown below.
import java.lang.Math; import java.awt.Graphics; public class CircleCell extends Cell implements Visualization { // . . . all other code of the original CircleCell Class public void draw(Graphics g) { int width = (int) getR()*2; int x = (int) (getX()-getR()); int y = (int) (getY()-getR()); g.drawOval(x,y,width,width); } } |