Hints for Chapter 2: Exploring Java
Problem 3: more message-passing
The effect of each message sent to the class SquareFigure is just as for Problem 2.
The effect of each message sent to the class CircleFigure is similar. To be more
specific,
- CircleFigure.moveRight(x) moves the circle right by x pixels;
- CircleFigure.moveLeft(x) moves the circle left by x pixels;
- CircleFigure.moveUp(x) moves the circle up by x pixels;
- CircleFigure.moveDown(x) moves the circle down by x pixels;
- CircleFigure.moveTo(x, y) moves the circle so that the x- and y-coordinates of its
centre are respectively x and y. These coordinates are measured from the upper-
left corner of the display region of the window;
- CircleFigure.setRadius(x) sets the radius of the circle to be
x pixels. The centre of
the circle is unaltered;
- CircleFigure.setColor(c) changes the colour of the circle to
c (provided c is either
Color.red, Color.blue or Color.green;
- CircleFigure.drawHollow( ) displays just the outline of the circle;
- CircleFigure.drawFilled ( ) displays the circle with its inside filled;
- CircleFigure.getXCentre( ) returns the x-coordinate of the centre of the circle;
- CircleFigure.getYCentre( ) returns the y-coordinate of the centre of the circle.