FileDocCategorySizeDatePackage
AirSpace.javaAPI DocExample2993Sun Feb 13 17:12:30 GMT 2000gui2000

AirSpace

public class AirSpace extends Object
The AirSpace class manages a number of Aircraft objects in a simulated airspace. It provides two communication objects:
  • Radar which provides information about the aircraft in the airspace.
  • Radio which provides two way communication with each individual aircraft.
author
T Balls
version
0.1, 12-12-99
see
gui2000.Radar
see
gui2000.Radio

Fields Summary
private Vector
aircraft
private Radio
radio
private Radar
radar
Constructors Summary
public AirSpace(String filename)
Create a new airspace populated with aircraft.

param
filename - the name of the file which is assumed to be be present in the gui2000 package with which to initialise the airspace.

Check the documentation for the assignment for the full list of data files that are available.

  FileInputStream fis = null;
      ObjectInputStream ois = null;
      try
      {  fis = new FileInputStream( filename );
         ois = new ObjectInputStream( fis );
         aircraft = (Vector)(ois.readObject());
      }
      catch( FileNotFoundException fnf )
      {  fnf.printStackTrace();
         System.out.println( "\n\n*** Error on opening file : " + filename );
         System.exit(0);
      }     
      catch( IOException ioe ) 
      {  ioe.printStackTrace();
         System.out.println( "\n\n*** Error reading file : " + filename );
         System.exit(0);
      }
      catch( ClassNotFoundException cnf ) 
      {  cnf.printStackTrace();
         System.out.println( "\n\n*** Error reading file : " + filename );
         System.exit(0);
      }
      
      radar = new Radar( aircraft );
      radio = new Radio( aircraft );
      synchronized( aircraft )
      {  for( int i = 0; i < aircraft.size(); i++ )
         {  ((Aircraft)(aircraft.elementAt(i))).addObserver( radio );
         }
      } 
      new ProximityDetector( aircraft );
   
Methods Summary
public RadargetRadar()

   
     
     return radar;
   
public RadiogetRadio()

  return radio;
   
public voidstartSimulation()
Begin the simulation

  synchronized( aircraft )
      {  for( int i = 0; i < aircraft.size(); i++ )
         {  new Thread( (Aircraft)(aircraft.elementAt(i)) ).start();
         }
 //        ((Aircraft)(aircraft.elementAt(0))).order( "RIGHT 315" );
 //        ((Aircraft)(aircraft.elementAt(0))).order( "CLIMB 5000" );
 //        ((Aircraft)(aircraft.elementAt(1))).order( "LEFT 45" );
 //        ((Aircraft)(aircraft.elementAt(1))).order( "DESCEND 2000" );
      }
      new Thread( radar ).start();