1   // JRobo    Example 9
2   //          Demonstrates polymorphism!
3   // Author:  David 5/9/99
4   
5   import java.awt.*;
6   import java.applet.*;
7   import java.util.ArrayList;
8   
9   public class JRoboTest extends Applet
10  {
11  
12      ArrayList theTeam;     // this holds a collection of JRobos
13  
14      public void paint( Graphics g )
15      {
16          // create three different types of JRobo
17          XJRobo aRobo = new XJRobo( g );
18          aRobo.move( -200, 0);
19  
20          ScaledXJRobo robby = new ScaledXJRobo( g );
21          robby.move( 80, 0);
22          robby.setScale( 1.5 );
23  
24          ColouredXJRobo friendly = new ColouredXJRobo( g );
25          friendly.move( 300, 0);
26          
27          // add each JRobo to the team
28          theTeam = new ArrayList();
29          theTeam.add( aRobo );
30          theTeam.add( robby );
31          theTeam.add( friendly );
32          
33          // tell each member of the team to draw a star
34          // (polymorphism means the each do it their way!)
35          for (int i = 0; i < theTeam.size(); i++)
36          {
37              // get next team member, someJRobo
38              XJRobo someJRobo = (XJRobo) theTeam.get( i );
39              
40              // have someJRobo draw star
41              someJRobo.l( 18 );
42              someJRobo.f( 150 );
43              for(int j = 0; j < 4; j++)
44              {
45                  someJRobo.l( 144 );
46                  someJRobo.f( 150 );
47              }
48          }
49      }
50      
51  } // end JRoboTest class
52