您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Apply Index

Apply Page # 9

Activity 9 – Methods that access an object's attributes

Run the GetSetMessages application. A window should open, presenting on the left a set of buttons to send messages to a MyCircle object and on the right a drawing area showing a small, black circle. Your computer should look similar to the screen shot in the figure below:

image33.gif (3977 bytes)

Perform the following tasks on the circle object by clicking the appropriate message buttons:

(1) Find out X position of circle

(Hint: Use the message button int getX() )

Note: The X position is not the centre, but the top, left of a square defining the circle's location

(2) set the X position of the circle to 200

(Hint: Use the message button setX( int ) )

(3) Find out the radius of the circle object

(4) Make the radius larger by scaling by a factor of 2

(5) Find out the radius again (now the circle is larger)

(6) Make the radius of the circle the same size as before doubling.

(Hint: Do this by scaling by a factor of 0.5)

(7) Try to make the radius zero by scaling by a factor of zero

Make a note of what happens – i.e. find out what the radius is after scaling by zero.

Discussion of Activity 9 – Methods that access an object's attributes

Back to Content

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg