/*
* File: AirSpace.java
*/
/**
* This package contains the files that support the GUI
* assignment for Semester 2 - 2000
*/
package gui2000;
import java.io.*;
import java.util.*;
/**
* The <code>AirSpace</code> class manages a number of <code>Aircraft</code>
* objects in a simulated airspace.
* It provides two communication objects:
* <UL>
* <LI><code>Radar</code> which provides information about the aircraft
* in the airspace.
* <LI><code>Radio</code> which provides two way communication with each
* individual aircraft.
* </UL>
*
*
* @author T Balls
* @version 0.1, 12-12-99
*
* @see gui2000.Radar
* @see gui2000.Radio
*/
public class AirSpace
{ /**
* 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.
* <P>Check the documentation for the assignment for the full list
* of data files that are available.
*/
public AirSpace( String filename )
{ 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 );
}
/**@shapeType AggregationLink
@associates <b>Aircraft</b>*/
private Vector aircraft = null;
private Radio radio = null;
private Radar radar = null;
public Radar getRadar()
{ return radar;
}
public Radio getRadio()
{ return radio;
}
/**
* Begin the simulation
*/
public void startSimulation()
{ 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();
}
}
|