FileDocCategorySizeDatePackage
RadarDisplay.javaAPI DocExample1637Sun Feb 13 17:05:24 GMT 2000None

RadarDisplay.java

// Generated by Together

import gui2000.*;
import java.awt.*;
import java.util.*;

public class RadarDisplay extends Frame implements Observer
{  public RadarDisplay()
   {  setTitle( "Radar Display" );
      add( theScreen );
      pack();
      setVisible( true );
   }

   private int screenSize = 500;
   private int halfScreen = screenSize/2;
   private RadarScreen theScreen = new RadarScreen( screenSize, screenSize );
   private Image im = null;                                  
   public void update( Observable o, Object a )
   {  if( o instanceof Radar )
      {  // if( im == null )
      	// remove the comment on the previous line to see a trail of
      	// markes left on screen
         {  im = createImage( screenSize, screenSize );
         }
         Graphics g = im.getGraphics();
         g.setColor( Color.black );
         Vector v = (Vector)a;
         for( int aircraft = 0; aircraft < v.size(); aircraft++ )
         {  AircraftData ad = (AircraftData)(v.elementAt( aircraft ));
            g.drawRect( halfScreen + ad.east*halfScreen/25000, halfScreen - ad.north*halfScreen/25000, 1, 1 );
         }
         g.dispose();
         theScreen.setImage( im );
         theScreen.repaint();
          
      }
   }    
   
}  

class RadarScreen extends Canvas
{  public RadarScreen( int w, int h )
   {  setSize( w, h );   
   }     
                                   
   private Image myImage;                      
   public void setImage( Image i)
   {  myImage = i;
   }
   
   public void paint( Graphics g )
   {  if( myImage != null )
      {  g.drawImage( myImage, 0, 0, null );
      }
   }
}