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

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)

 

Content Index

Content Page # 16

The "BallWorld" classes

Now we have a Ball class, we need a class that creates a window on screen and a ball object to display in that window. We will create an application class called BallWorld for this purpose.

There are lots of technical details required to get an application class to create a window and so on. We will not worry about these details in this example, but concentrate on how Java implements the following concepts:

      a variable that refers to an instance of a class (i.e. that refers to an object)
      an application sending messages to a Ball object

Rather than immediately look at a complex version of class BallWorld dealing with more than one bouncing ball, we shall first look at a simple BallWorld class, and look at how it can be refined in stages into a more sophisticated version. The sequence of refinements we shall go through are as follows:

      Version 1: display a static Ball object
      Version 2: display a Ball object in one place, then a second place
      Version 3: display a moving Ball object
      Version 4: display a moving Ball object that can "bounce" off the sides of its window
      Version 5: display 2 bouncing Ball objects
      Version 6: display 2 bouncing Ball objects (but reducing code)
      Version 7: display many bouncing Ball objects
      Version 8: display a bouncing Ball, and a bouncing RandomBall

Each of these refinements illustrates either some object concept in Java, or some way in which object-oriented software systems can be refined incrementally in a structured way.

Back to top

basicline.gif (169 bytes)

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