import java.awt.*;
import java.applet.*;
import java.lang.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.sql.*;
//import XeoMenu;
public class focas extends Applet
{
  Color bgcolor = new Color(0,0,200);
  //XeoMenu go_to_table;
  Button laser,relay_optics_t,telescope_t,location_t,data_format,link_range,
    noise_sources,atmosphere,amplifier,detector,relay_optics_r,telescope_r,
    load_link,save_link,location_r,pointing;
  Choice links;
  Label t_laser,t_telescope_t,t_location_t,t_amplifier,t_detector,t_telescope_r,t_title,t_location_r,heading,t_link,t_transmitter,t_reciever;
  
  // Link Parameters
  String LinkName = new String("SP-TMF");
  
  // LASER PARAMETERS
  String LaserName = new String("Q-switched ND:YAG");
  boolean LaserType = true; //if true laser type is CW if false laser type is Pulsed
  boolean Wavelength_units = true; //if true unit is nm if false unit is um
  boolean Power_units = false; //if true unit is mW if false unit is W
  boolean Spectral_units = false; //if true unit is = if false unit is nm
  double LaserWavelength=1.064E-6;
  double LaserAvgPower=10;
  double LaserSpectralWidth = 10 ;
  double LaserPulseWidth = 20;
  
  //Relay optics Transmitter Parameteres
  double RelayOpticsTrans = 0;
  boolean Relay_units = true; //if true units is % else dB
  
  //Transmitter Telescope Properties
  String T_TelescopeName = new String("X2000");
  double ApertureDiameter  = .3;
  double SecondaryObsuration =.03 ;
  double TelescopeLosses =20 ;
  double Surface_Quality =16 ;
  double BeamWidth =0 ;
  boolean Aperture_units = true; // same convention...the button to the left is true if on
  boolean Secondary_units = false;
  boolean TelescopeLosses_units = false;
  boolean Surface_units = false;
  boolean BeamProfile = true;
  boolean inSpace = true;
  //Receiver Telescope Props
  String R_TelescopeName = new String("X2000");
  double R_ApertureDiameter  = .3;
  double R_SecondaryObsuration =.03;
  double R_TelescopeLosses =20 ;
  boolean R_Aperture_units = true; // same convention...the button to the left is true if on
  boolean R_Secondary_units = true;
  boolean R_TelescopeLosses_units = false;
  boolean R_inSpace = true;
  double RxSurfErr=0;
  //Pointing (Transmitter)
  double PointingBeamwidth = 0;
  double PointingOffset = 0;
  double PointingJitter = 0;
  boolean PointingOffset_units = true;
  boolean PointingJitter_units = true;
  // Reciever Location
  double Altitude= 0.0;
  double Latitude = 0.0;
  String Location = "TMF";
  String alt_units = "m";
  int r_index =15;
  
  // Data Format 
  double LaserMod=0,PulseSlot=0,K=0,DataRate=0,BER=0;
  double P=0,N=0;
  int Pindex=0,Nindex=0;
  boolean Modtype=true;
  String Coding_type="None";
  String DataRate_units = "Kbps";
  
  // Noise Sources
  String Stars  = "None";
  String Planets = "None";
  String Conditions = "Dark";
  double Distance = 0;
	
  // Atmosphere
  double Seeing= 9.69628,Trans=.85,Angle=70;
  boolean usedefault = false,Seeing_units= true;
  
  // Link Range;
  double Range = 0;
  //Amplifier
  String AmpModel = "Transimpedance model";
  boolean Hz_units = true;
  double AmpNEI=0,ampBANDWIDTH=0,ampRANGE=0,ampGAIN=0;
  //Detector
  double Quantum=0,BulkDark=0,SurfaceDark=0,RiseFall=0,DetectorDiameter=0,Capacitance=0,Gain=0,Ionization=0;
  String Detector="Si APD IR Enhanced (EG&G C30954E)";
  //Reciever Relay Optics
  double  Field=0,Truncation=0,Split=0,Redundancy=0,Pointing=0,Optical=0,Spectral=0,Peak=0;
  boolean  truncation_units=true,split_units=true,redundancy_units=true,pointing_units=true,optical_units=true;
  
  //Location transmitter
  String Location_t = "GEO";
  double Altitude_t= 0.0;
  double Latitude_t = 0.0;
  String alt_units_t = "m";
  int t_index = 5;
  // Parameters not in pop-up windows
  String newTRANSLoc, newRECloc,atmosMODEL,detectorTYPE;
  boolean LaserInSpace;
  double laser_variation,LS_TxLossMO,TxLossTO,TxLossSS;
  double pt_allowance,atm_adj,RxSrcDist,RxLossTO,RxLossSS;
  double coding_adj;
  //array of wavelengths needed to calculate Quantum efficiency
  int QE_wavelengths[] = new int[76];
  
  // DATABASE STUFF
  Connection C;
  String url = "jdbc:mysql://localhost:3306/focas";
 
  public void init() 
    {
      setBackground(bgcolor);
      make_begin(); 
     
      int step=0;
      for(int i =0;i<76;i++,step+=20)
	{
	  QE_wavelengths[i] = 500+step;
	}
      try
	{
	  Class.forName("org.gjt.mm.mysql.Driver").newInstance();
	  System.out.println("Done");
	}
      catch(Exception E){System.err.println("Unable to load driver");}
      
      try
	{
	  C = DriverManager.getConnection(url,"birju","patel");
	  String ex = "SELECT * " + "FROM laser " + "WHERE name = '" + LaserName + "' ";
	  Statement stmt = C.createStatement();
	  
	  System.out.println(ex);
	  ResultSet results = stmt.executeQuery(ex);
	  
	 
	  System.out.println( results.getString(1));
	  System.out.println( results.getString(2));
	}
      catch (SQLException d)
	{
	  System.out.println("SQLException: " + d.getMessage());
	  System.out.println("SQLState: " + d.getSQLState());
	  System.out.println("VendorError: " + d.getErrorCode());
	}
      /*  try
	{
	  getinfo();
	}
	catch(IOException esa){}*/
      
    }
  
   
  public void paint(Graphics g)
    {
      paintComponents(g);          
    }
  public void make_begin()
    {
      Label version = new Label("Java v1.0");
      GridBagLayout gridbag = new GridBagLayout();
      Panel panel1,panel2,panel3,panel4,panel5;
      // Create all buttons
      laser = new Button("Laser");
      relay_optics_t = new Button("Relay Optics");
      relay_optics_r = new Button("Relay Optics");
      telescope_t = new Button("Telescope");
      telescope_r = new Button("Telescope");
      location_t = new Button("Location");
      location_r = new Button("Location");
      data_format = new Button("Data Format");
      link_range = new Button("Link Range");
      noise_sources = new Button("Noise Sources");
      atmosphere = new Button("Atmosphere");
      amplifier = new Button("Amplifier");
      detector = new Button("Detector");
      pointing = new Button("Pointing");
      
      save_link = new Button("Save Link");
     
      laser.setBackground(Color.lightGray);
      relay_optics_t.setBackground(Color.lightGray);
      relay_optics_r.setBackground(Color.lightGray); 
      telescope_t.setBackground(Color.lightGray);
      telescope_r.setBackground(Color.lightGray);;
      location_t.setBackground(Color.lightGray);
      location_r.setBackground(Color.lightGray); 
      data_format.setBackground(Color.lightGray);
      link_range.setBackground(Color.lightGray); 
      noise_sources.setBackground(Color.lightGray); 
      atmosphere.setBackground(Color.lightGray);
      amplifier.setBackground(Color.lightGray);
      detector.setBackground(Color.lightGray);
      save_link.setBackground(Color.lightGray); 
      //go_to_table.setBackground(Color.white);
      pointing.setBackground(Color.lightGray);
      links = new Choice();
      links.addItem("Gold Downlink");
      links.addItem("Mars Downlink (Night, APD)");
      links.addItem("Mars Downlink (Night, PMT)");
      links.addItem("SP-TMF");
      links.addItem("Europa Downlink (Day, APD)");
      links.addItem("Europa Downlink (Night, PMT)");
      links.setBackground(Color.lightGray);
      links.select(LinkName);
      t_title = new Label("Gold Downlink");
      t_title.setFont(new Font("Helvetica",Font.BOLD,20));
      t_laser = new Label(LaserName);
      t_telescope_t = new Label(T_TelescopeName);
      t_telescope_r = new Label(R_TelescopeName);
      t_location_r = new Label(Location);
      t_location_t = new Label(Location_t);
      t_amplifier = new Label(AmpModel);
      t_detector = new Label(Detector);
      t_link = new Label("Link: ");
      t_transmitter = new Label("Transmitter");
      t_reciever = new Label("Receiver");
      
      t_title.setForeground(Color.white);
      t_laser.setForeground(Color.white);
      t_telescope_t.setForeground(Color.white);
      t_telescope_r.setForeground(Color.white);
      t_location_t.setForeground(Color.white);
      t_location_r.setForeground(Color.white);
      t_amplifier.setForeground(Color.white);
      t_detector.setForeground(Color.white);
      t_link.setForeground(Color.white);
      t_transmitter.setForeground(Color.yellow);
      t_reciever.setForeground(Color.yellow);
      version.setForeground(Color.yellow);
      version.setFont(new Font("Helvetica",Font.BOLD,12));
      //go_to_table = new XeoMenu(this);
      t_link.setFont(new Font("Helvetica",Font.BOLD,16));
      t_transmitter.setFont(new Font("Helvetica",Font.BOLD,16));
      t_reciever.setFont(new Font("Helvetica",Font.BOLD,16));
      t_title.setAlignment(t_title.CENTER);
      t_telescope_t.setAlignment(t_telescope_t.CENTER);
      t_telescope_r.setAlignment(t_telescope_r.CENTER);
      t_location_t.setAlignment(t_location_t.CENTER);
      t_amplifier.setAlignment(t_amplifier.CENTER);
      t_detector.setAlignment(t_detector.CENTER);
      t_location_r.setAlignment(t_location_r.CENTER);
      this.setLayout(gridbag);
      heading = new Label("Free-space Optical Communications Analysis Software");
      heading.setFont(new Font("Helvetica",Font.BOLD,22));
      heading.setForeground(Color.yellow);
      panel1 = new Panel(); //Center title panel
      panel1.setLayout(gridbag);
      panel1.setBackground(Color.black);
      constrain(panel1,t_title,0,0,3,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      panel2 = new Panel();
      panel2.setBackground(new Color(91,91,255));
      panel2.setLayout(gridbag);
      
      constrain(panel2,laser,0,0,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel2,t_laser,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel2,relay_optics_t,0,2,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,20,0,0,0);
      constrain(panel2,telescope_t,0,3,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,30,0,0,0);
      constrain(panel2,t_telescope_t,0,4,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel2,pointing,0,5,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,30,0,0,0);
      constrain(panel2,location_t,0,7,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,30,0,0,0);
      constrain(panel2,t_location_t,0,8,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      
      panel3 = new Panel();
      panel3.setBackground(new Color(0,0,200));
      panel3.setLayout(gridbag);
      constrain(panel3,data_format,0,0,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel3,link_range,0,1,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,20,0);
      constrain(panel3,noise_sources,0,6,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,20,0,0,0);
      constrain(panel3,atmosphere,0,7,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      
      panel4 = new Panel();
      panel4.setBackground(new Color(91,91,255));
      panel4.setLayout(gridbag);
      constrain(panel4,amplifier,0,0,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel4,t_amplifier,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel4,detector,0,2,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel4,t_detector,0,3,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,10,0);
      constrain(panel4,relay_optics_r,0,4,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,10,0,0,0);
      constrain(panel4,telescope_r,0,5,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,35,0,0,0);
      constrain(panel4,t_telescope_r,0,6,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(panel4,location_r,0,7,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,30,0,0,0);
      constrain(panel4,t_location_r,0,8,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      panel5 = new Panel();
      panel5.setLayout(gridbag);
      constrain(panel5,t_link,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
      constrain(panel5,links,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,7,0,0,10);
      constrain(panel5,save_link,2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      //constrain(panel5,go_to_table,3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      Panel spa = new Panel();
      spa.setLayout(gridbag);
      Panel spa1 = new Panel();
      spa1.setLayout(gridbag);
      
      constrain(spa,heading,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(this,spa,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(spa1,version,1,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,50,0);
      constrain(spa1,t_transmitter,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(spa1,t_reciever,2,2,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(spa1,t_title,1,2,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(spa1,panel2,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.0,0.0,0,0,0,0);
      constrain(spa1,panel3,1,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      constrain(spa1,panel4,2,3,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.0,0.0,0,0,0,0);
      constrain(spa1,panel5,1,5,1,1,GridBagConstraints.NONE,GridBagConstraints.SOUTH,0.0,0.0,75,0,0,0);
      constrain(this,spa1,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
      
      //go_to_table.initialize();
      //go_to_table.repaint();
      //constrain(this, go_to_table, 0, 2, 0, 0,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
    }      
  
  public boolean action(Event event,Object arg) 
    {
      if (event.target == links)
	{
	  
	  LinkName = links.getSelectedItem();
	  t_title.setText(LinkName);
	  t_title.setAlignment(t_title.CENTER);
	  try{getinfo();}
	  catch(IOException ew){}
	  t_location_r.setText(Location);
	  t_location_r.setAlignment(t_location_r.CENTER);
	  t_location_t.setText(Location_t);
	  t_location_t.setAlignment(t_location_t.CENTER);
	  t_laser.setText(LaserName);
	  t_laser.setAlignment(t_laser.CENTER);
	  t_telescope_t.setText(T_TelescopeName);
	  t_telescope_t.setAlignment(t_telescope_t.CENTER);
	  t_telescope_r.setText(R_TelescopeName);
	  t_telescope_r.setAlignment(t_telescope_r.CENTER);
	  t_detector.setText(Detector);
	  t_detector.setAlignment(t_detector.CENTER);
	  t_amplifier.setText(AmpModel);
	  t_amplifier.setAlignment(t_amplifier.CENTER);
	  
	  
	  
	  return true;
	  
	}
      else if(event.target == location_r)
	{
	  location_r_frame p = new location_r_frame("Reciever Location");
	  t_location_r.setText(Location);
	  t_location_r.setAlignment(t_location_r.CENTER);
	  return true;
	}
      else if(event.target == pointing)
	{
	  pointing_frame w = new pointing_frame("Transmitter Pointing");
	  return true;
	}
      else if (event.target == relay_optics_t)
	{
	  relay_frame x = new relay_frame("Relay Optics");
	  return true;
	  
	}
      else if (event.target == laser)
	{
	  laser_frame f = new laser_frame("Laser Parameters");
	  return true;
	}
      else if(event.target == telescope_t)
	{
	  telescope_t_frame d = new telescope_t_frame("Transmitter Telescope");
	  return true;
	}
      else if(event.target == data_format)
	{
	  data_format_frame t = new data_format_frame("Data Format");
	  return true;
	}
      else if(event.target == noise_sources)
	{
	  noise_sources_frame y = new noise_sources_frame("Noise Sources");
	  return true;
	}
      else if(event.target == atmosphere)
	{
	  atmosphere_frame o = new atmosphere_frame("Atmosphere Parameters");
	  return true;
	}
      else if(event.target == amplifier)
	{
	  amplifier_frame p = new amplifier_frame("Pre-Amplifier");
	  return true;
	}
      else if(event.target == detector)
	{
	  detector_frame zc = new detector_frame("Detector");
	  return true;
	}
      else if(event.target == relay_optics_r)
	{
	  r_relay_optics_frame op = new r_relay_optics_frame("Reciever Relay Optics");
	  return true;
	}
      else if(event.target == location_t)
	{
	  location_t_frame we = new location_t_frame("Transmitter Location");
	  return true;
	}
      else if(event.target == telescope_r)
	{
	  telescope_r_frame kl = new telescope_r_frame("Reciever Telescope");
	  return true;
	}
      else if(event.target == link_range)
	{
	  link_range_frame ad = new link_range_frame("Link Range");
	  return true;
	}
      
      else  return false;
    }
  
  public class amplifier_frame extends Frame
  {
    private Button ok,cancel;
    private Label label1,label2;
    private Choice amplifier;
    private CheckboxGroup b_hz;
    private Checkbox[] cb_hz;
    private TextField nei,dynamic,bandwidth,ampgain;
    public amplifier_frame(String title)
      {
	super(title);
	ok = new Button("Ok");
	cancel  = new Button("Cancel");
	amplifier = new Choice();
	amplifier.addItem("");
	amplifier.addItem("Transimpedance model");
	amplifier.addItem("High-Impedance model");
	amplifier.addItem("Fujitsu FMM321CP");
	amplifier.addItem("Fujitsu FMM324CP");
	amplifier.addItem("Fujitsu FMM322CP");
	amplifier.addItem("Fujitsu FMM323CP");
	amplifier.addItem("AMI 322");
	amplifier.select(AmpModel);
      
	nei = new TextField(String.valueOf(AmpNEI),10);
	dynamic = new TextField(String.valueOf(ampRANGE),10);
	bandwidth = new TextField(String.valueOf(ampBANDWIDTH),10);
	ampgain = new TextField(String.valueOf(ampGAIN),10);
     
	b_hz = new CheckboxGroup();
	cb_hz = new Checkbox[2];
	cb_hz[0] = new Checkbox("MHz",b_hz,Hz_units);
	cb_hz[1] = new Checkbox("GHz",b_hz,!Hz_units);
	Panel panel1 = new Panel();
	Panel panel2 = new Panel();
	Panel panel3 = new Panel();
	
	GridBagLayout gridbag = new GridBagLayout();
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
       
	this.setLayout(gridbag);
	constrain(panel1,new Label("Name: "),0,0,1,1);
	constrain(panel1,amplifier,1,0,1,1);
	
	constrain(panel2,new Label("Amplifier Gain (V/A)"),0,0,1,1);
	constrain(panel2,ampgain,1,0,1,1);
	constrain(panel2,new Label("Bandwidth"),0,1,1,1);
	constrain(panel2,bandwidth,1,1,1,1);
	constrain(panel2,cb_hz[0],2,1,1,1);
	constrain(panel2,cb_hz[1],3,1,1,1);
	constrain(panel2,new Label("Dynamic Range (dB)"),0,2,1,1);
	constrain(panel2,dynamic,1,2,1,1);
	constrain(panel2,new Label("Noise Equivalent Current"),0,3,1,1);
	constrain(panel2,nei,1,3,1,1);
	constrain(panel2,new Label("A/sqrt(Hz)"),2,3,1,1);
	
	
	constrain(panel3,ok,0,0,1,1,0,0,0,10);
	constrain(panel3,cancel,1,0,1,1,0,10,0,0);
	constrain(this,panel1,0,0,1,1);
	constrain(this,panel2,0,1,1,1);
	constrain(this,panel3,0,2,1,1,20,0,0,0);
	this.pack();
	this.show();
      }
    public boolean action(Event e,Object arg)
      {
	if (e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	AmpModel = amplifier.getSelectedItem();
	t_amplifier.setText(AmpModel);
	t_amplifier.setAlignment(t_amplifier.CENTER);
      }
    
  }
  public class location_t_frame extends Frame
  { private Button ok,cancel;
    private Label label1,label2,label3;
    private TextField t_altitude,t_latitude;
    private CheckboxGroup b_units;
    private Checkbox[] cb_units;
    private Choice c_locations;
    public location_t_frame(String Title)
      {
	super(Title);
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	label1 = new Label("Altitude: ");
	label2 = new Label("Latitude: ");
	label3 = new Label("Location: ");
	t_altitude = new TextField(String.valueOf(Altitude_t),10);
	t_latitude = new TextField(String.valueOf(Latitude_t),10);
	b_units = new CheckboxGroup();
	cb_units = new Checkbox[3];
	cb_units[0] = new Checkbox("m",b_units,(alt_units_t == "m"));
	cb_units[1] = new Checkbox("ft",b_units,(alt_units_t == "ft"));
	cb_units[2] = new Checkbox("km",b_units,(alt_units_t == "km"));
	c_locations = new Choice();
	c_locations.addItem("Moon");
	c_locations.addItem("Shuttle");
	c_locations.addItem("Space Station");
	c_locations.addItem("LEO");
	c_locations.addItem("GEO");
	c_locations.addItem("Venus");
	c_locations.addItem("Mars");
	c_locations.addItem("Jupiter");
	c_locations.addItem("Saturn");
	c_locations.addItem("Uranus");
	c_locations.addItem("Neptune");
	c_locations.addItem("Pluto");
	c_locations.addItem("Comet");
	c_locations.addItem("Asteroid");
	c_locations.addItem("Other");
	c_locations.addItem("TMF");
	c_locations.addItem("Starfire");
	c_locations.addItem("Strawberry Peek");
	c_locations.addItem("Mt. Lemmon");
	c_locations.addItem("Goldstone");
	c_locations.addItem("Mesa");
	c_locations.addItem("JPL");
	c_locations.select(Location_t);
	t_index=c_locations.getSelectedIndex();
	System.out.println(Location_t);
	Panel panel1,panel2,panel3,panel4;
	panel1 = new Panel();
	panel2 = new Panel();
	panel3 = new Panel();
	panel4 = new Panel();
	
	
	GridBagLayout gridbag = new GridBagLayout();
	this.setLayout(gridbag);
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	
	constrain(panel1,label3,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel1,c_locations,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,label1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,t_altitude,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_units[0],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_units[1],3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_units[2],4,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel3,label2,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel3,t_latitude,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel4,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,10);
	constrain(panel4,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,0);
	
	constrain(this,panel1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel2,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel3,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(this,panel4,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	this.pack();
	this.show();
	
	
      }
    
    
    public boolean action(Event e,Object arg)
      {
	if(e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	Altitude_t = (Double.valueOf(t_altitude.getText())).doubleValue();
	Latitude_t = (Double.valueOf(t_latitude.getText())).doubleValue();
	alt_units_t = (b_units.getCurrent()).getLabel();
	Location_t = c_locations.getSelectedItem();
	t_index = c_locations.getSelectedIndex();
	t_location_t.setText(Location_t);
	t_location_t.setAlignment(t_location_t.CENTER);
      }
	
    
   
  }
  
  public class link_range_frame extends Frame
  {
    private Button ok,cancel;
    private TextField range;
    public link_range_frame(String title)
      {
	super(title);
	ok= new Button("Ok");
	cancel = new Button("Cancel");
	GridBagLayout gridbag = new GridBagLayout();
	this.setLayout(gridbag);
	Panel panel1 = new Panel();
	panel1.setLayout(gridbag);
	Panel panel2 = new Panel();
	panel2.setLayout(gridbag);
	Choice c_locations = new Choice();
	c_locations.addItem("Moon");
	c_locations.addItem("Shuttle");
	c_locations.addItem("Space Station");
	c_locations.addItem("LEO");
	c_locations.addItem("GEO");
	c_locations.addItem("Venus");
	c_locations.addItem("Mars");
	c_locations.addItem("Jupiter");
	c_locations.addItem("Saturn");
	c_locations.addItem("Uranus");
	c_locations.addItem("Neptune");
	c_locations.addItem("Pluto");
	c_locations.addItem("Comet");
	c_locations.addItem("Asteroid");
	c_locations.addItem("Other");
	c_locations.addItem("TMF");
	c_locations.addItem("Starfire");
	c_locations.addItem("Strawberry Peek");
	c_locations.addItem("Mt. Lemmon");
	c_locations.addItem("Goldstone");
	c_locations.addItem("Mesa");
	c_locations.addItem("JPL");
	c_locations.select(Location_t);
	t_index = c_locations.getSelectedIndex();
	c_locations.select(Location);
	r_index = c_locations.getSelectedIndex();
	
	
	try {getinfo();}
	catch(IOException x){}
	range = new TextField(String.valueOf(Range),10);
	
	constrain(panel1,new Label("Distance from "),0,0,1,1);
	constrain(panel1,new Label(Location_t),1,0,1,1);
	constrain(panel1,new Label("to  " + Location +"  is"),2,0,1,1);
	constrain(panel1,range,3,0,1,1);
	constrain(panel1,new Label("km"),4,0,1,1);
	constrain(this,panel1,0,0,1,1);
	constrain(panel2,ok,0,1,1,1,0,0,0,10);
	constrain(panel2,cancel,1,1,1,1,0,10,0,0);
	constrain(this,panel2,0,1,1,1,20,0,0,0);
	this.pack();
	this.show();
      }
    public boolean action(Event e, Object arg)
      {
	if(e.target == ok)
	  { 
	    Range = (Double.valueOf(range.getText())).doubleValue();
	    dispose();
	    return true;
	  }
	else if(e.target==cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void getinfo() throws IOException
      {
	
	URL url = new URL("http://www331.jpl.nasa.gov/group1/focas_birju/range.txt");
	URLConnection connection = url.openConnection();
	connection.connect();
	
	DataInputStream in = new DataInputStream(connection.getInputStream());
	int i;
	if(t_index>14) t_index = 15;
	if(r_index>14) r_index = 15;
	for(i = 0;i<t_index;i++) in.readLine();
	String temp = new String(in.readLine());
	StringTokenizer token = new StringTokenizer(temp);
	for(i=0;i<r_index;i++) token.nextToken();
	temp = token.nextToken();
	Range = (Double.valueOf(temp)).doubleValue();
	
      }
  }
public class link_table extends Frame
{
  private Button Update;
  private Button ok,cancel;
     
  public link_table(String title1)
    {
      super(title1);
    
      //      createScrollBar(Scrollbar this);
 
      setBackground(new Color(0,0, 200));
      Panel panel1;
      panel1 = new Panel();
      Panel panel2;
      panel2 = new Panel();
      GridBagLayout gridbag1 = new GridBagLayout();
      panel1.setLayout(gridbag1);
      panel1.setForeground(Color.yellow);
      constrain(panel1, t_link, 0, 1, 5, 5, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 11, 11, 0, 20, 0, 20);
      
      panel2.setFont(new Font("Helvetica",Font.BOLD,12));
      panel2.setForeground(Color.yellow);
      panel2.setLayout(gridbag1); 
      constrain(panel2, new Label("Link Summary"), 0, 2, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 11, 11, 0, 320, 0, 320);
      Panel panel3 = new Panel();
      panel3.setLayout(gridbag1);
      panel3.setFont(new Font("Helvetica",Font.BOLD,12));
      panel3.setForeground(Color.yellow);
      constrain(panel3, new Label("Detailed Link Table"), 0, 4, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 11, 11, 0, 320, 0, 320); 
      Panel panel4 = new Panel();
      panel4.setLayout(gridbag1);
      panel4.setBackground(new Color(91,91,255));
      panel4.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel4.setForeground(Color.white);
      constrain(panel4, new Label("Transmitter-GEO"), 0, 5, 1,1);     
  
      Panel panel5;
      panel5 = new Panel();
      panel5.setLayout(gridbag1);
   
      TextArea textarea = new TextArea(3, 80);
      constrain(panel5, textarea, 1, 2, 1, 1);
     
      textarea.setText("Link Range\t   ");
      String val1;
      val1 = Double.toString(Range);
      textarea.appendText(val1);
      textarea.appendText("\nData rate");
      textarea.appendText("\nCoded BER");
      textarea.appendText("\n\tBit rate");
      textarea.appendText("\n\tUncoded BER");
      textarea.appendText("\nTransmit power");
      textarea.appendText("\nTransmit loss");
      textarea.appendText("\nTransmitter gain");
      textarea.appendText("\nPointing losses");
      textarea.appendText("\nSpace loss");
      textarea.appendText("\nAtmospheric losses");
      textarea.appendText("\nReceiver gain");
      textarea.appendText("\nReceiver optics losses");
      textarea.appendText("\nReceived signal");
      textarea.appendText("\nBackground signal level");
      textarea.appendText("\nRequired signal level");
      textarea.appendText("\nAllowances and Adjustments");
      textarea.appendText("\nLink Margin");
    
      Panel panel6 = new Panel();
      panel6.setLayout(gridbag1);
      TextArea textarea1 = new TextArea(3, 80);
      constrain(panel6, textarea1, 0, 6, 1, 1);
      textarea1.setText("\nLaser (CW LD:830)");
      textarea1.appendText("\n \tPeak power");
      textarea1.appendText("\n \tAverage power");
      textarea1.appendText("\n \tWavelength");
      textarea1.appendText("\n \tPhoton energy");
      textarea1.appendText("\n \tWord time (including dead time)");
      textarea1.appendText("\n \tPulse width");
      textarea1.appendText("\n \tPulse width to slot width ratio");
      textarea1.appendText("\n \tSlot width or integration time");
      textarea1.appendText("\n \tDead time");
      textarea1.appendText("\n \tDuty cycle");
      textarea1.appendText("\n \tPulse repetition rate");
      textarea1.appendText("\n \tEnergy per pulse");
      textarea1.appendText("\n \tPhotons per pulse");
      textarea1.appendText("\n \tPeak power");
      textarea1.appendText("\n \tElectrical-to-optical power efficiency");
      textarea1.appendText("\n \tPrime pwer");
      textarea1.appendText("\n \n Transmit Optics");
      textarea1.appendText("\n \tOptics efficiency");
      textarea1.appendText("\n \nTelescope (LCE on ETS-VI)");
      textarea1.appendText("\n\tOn-axis gain");
      textarea1.appendText("\n\tTransmit beamwidth");
      textarea1.appendText("\n\tIdeal beamwidth");
      textarea1.appendText("\n\tAperture diameter");
      textarea1.appendText("\n\tSecondary obscuration");
      textarea1.appendText("\n\tObscuration ratio");
      textarea1.appendText("\n\tAperture-to-beamwidth ratio");
      textarea1.appendText("\n\tOptical surface quality(1/fraction of wavelength)");
      textarea1.appendText("\n\tStrehl ratio");
      textarea1.appendText("\n\tTelescope optical losses");
      textarea1.appendText("\n\tLoss from support structure");
      textarea1.appendText("\nPointing");
      textarea1.appendText("\n\tAllowance for pointing loss");
      textarea1.appendText("\n\tJitter (% of beamwidth)");
      textarea1.appendText("\n\tBias (% of beamwidth)");
      textarea1.appendText("\n\tRMS pointing jitter");
      textarea1.appendText("\n\tBias pointing error");
      textarea1.appendText("\n\tMispoint angle");
      textarea1.appendText("\n\tLoss at mispoint angle");
      textarea1.appendText("\n\tExpected value of pointing error");
      textarea1.appendText("\n\tMean loss (Gaussian beam pattern");
      textarea1.appendText("\n\tPointing-induced fade probability");
    
      Panel panel7 = new Panel();
      panel7.setLayout(gridbag1);
      panel7.setBackground(new Color(91,91,255));
      panel7.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel7.setForeground(Color.white);
      constrain(panel7, new Label("Channel"), 0, 7, 1, 1);
      Panel panel8 = new Panel();
      panel8.setLayout(gridbag1);
      TextArea textarea2 = new TextArea(3, 80);
      constrain(panel8, textarea2, 0, 8, 1, 1);
      textarea2.setText("\nSpace Loss");
      textarea2.appendText("\n\tTransmitter to receiver distance");
      textarea2.appendText("\n\tBeam size at receiver location");
      textarea2.appendText("\n\nAtmospheric loss");
      textarea2.appendText("\n\tTransmission at zenith");
      textarea2.appendText("\n\tObservation angle from zenith");
      textarea2.appendText("\n\tAir mass");
      textarea2.appendText("\n\tSeeing at zenith");
      Panel panel9 = new Panel();
      panel9.setLayout(gridbag1);
      panel9.setBackground(new Color(91,91,255));
      panel9.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel9.setForeground(Color.white);
      constrain(panel9, new Label("Receiver (TMF)"), 0, 9, 1, 1);
      Panel panel10 = new Panel();
      panel10.setLayout(gridbag1);
      TextArea textarea3 = new TextArea(3, 80);
      constrain(panel10, textarea3, 0, 10, 1, 1);
      textarea3.setText("\n\nTelescope (TMF 48-inch)");
      textarea3.appendText("\n\tGain");
      textarea3.appendText("\n\tAperture diameter");
      textarea3.appendText("\n\tSecondary obscuration");
      textarea3.appendText("\n\tObscuration ratio");
      textarea3.appendText("\n\tTelescope focal length");
      textarea3.appendText("\n\tTelescope F#");
      textarea3.appendText("\n\tStrehl ratio");
      textarea3.appendText("\n\tTelescope losses");
      textarea3.appendText("\nRelay Optics");
      textarea3.appendText("\n\tFilter loss");
      textarea3.appendText("\n\tAcquisition/Tracking split loss");
      textarea3.appendText("\n\tLoss due to redundant detectors");
      textarea3.appendText("\n\tReceiver pointing loss");
      textarea3.appendText("\n\tDetecter truncation loss");
      textarea3.appendText("\n\t\tActual blur size (FW at 1/e^2 points)");
      textarea3.appendText("\n\t\tIdeal spot size (FW at 1/e^2 points)");
      textarea3.appendText("\n\tOther losses");
      textarea3.appendText("\n\nDetector (EGrand APD C30956E)");
      textarea3.appendText("\n\nAmplifier (AMI 322)");
      textarea3.appendText("\n\tNoise equivalent current (NEI)");
      textarea3.appendText("\n\tDetector/preamplifier bandwidth");
      
      Panel panel11 = new Panel();
      panel11.setLayout(gridbag1);
      panel11.setBackground(new Color(91,91,255));
      panel11.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel11.setForeground(Color.white);
      constrain(panel11, new Label("Link Margin"), 0, 11, 1, 1);
      
      Panel panel12 = new Panel();
      panel12.setLayout(gridbag1);
      TextArea textarea4 = new TextArea(3, 80);
      constrain(panel12, textarea4, 0, 12, 1, 1);
      textarea4.setText("\nPeak power received at detector");
      textarea4.appendText("\nRequired power");
      textarea4.appendText("\n\tNon-ideal bit synchronization");
      textarea4.appendText("\n\tPulse amplitude variations");
      textarea4.appendText("\n\tMcIntyre statistics (for APD)");
      textarea4.appendText("\n\tCode gain adjustments");
      textarea4.appendText("\n\tAllowance for atmospheric effects");
      textarea4.appendText("\nLink margin");
      textarea4.appendText("\nPointing-induced fade probability");
      textarea4.appendText("\nAtmosphere-induced fade probability");
      
      Panel panel13 = new Panel();
      panel13.setLayout(gridbag1);
      panel13.setBackground(new Color(91,91,255));
      panel13.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel13.setForeground(Color.white);     
      constrain(panel13, new Label("Coding"), 0, 12, 1, 1);
      Panel panel14 = new Panel();
      panel14.setLayout(gridbag1);
      TextArea textarea5 = new TextArea(3, 80);
      constrain(panel14, textarea5, 0, 13, 1, 1);
      textarea5.setText("\nNo Coding");
      textarea5.appendText("\n\tNumber of symbols (N=M=1)");
      textarea5.appendText("\n\tNumber of information symbols (k)");
      textarea5.appendText("\n\tMinimum distance (Dmin)");
      textarea5.appendText("\nCode rate (K/N)");
      textarea5.appendText("\nUncoded BER");
      textarea5.appendText("\n\tUncoded word error rate");
      textarea5.appendText("\nCoded BER");
      textarea5.appendText("\n\tDesired coded BER");
      Panel panel15 = new Panel();
      panel15.setLayout(gridbag1);
      panel15.setBackground(new Color(91,91,255));
      panel15.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel15.setForeground(Color.white);
      constrain(panel15, new Label("Required Signal Power Calculation"), 0, 13, 1, 1);
      
      Panel panel16 = new Panel();
      panel16.setLayout(gridbag1);
      TextArea textarea6 = new TextArea(3, 80);
      constrain(panel16, textarea6, 0, 14, 1, 1);
      textarea6.setText("\nEGandG APD C30956E Detector with AMI 322 Amplifier");
      textarea6.appendText("\n\tDetector quantaum efficiency");
      textarea6.appendText("\n\tDetector ionization ratio");
      textarea6.appendText("\n\tModulation extinction ratio");
      textarea6.appendText("\n\n Required peak power");
      textarea6.appendText("\n\tSignal photons per pulse");
      textarea6.appendText("\n\tPhotons per bit");
      textarea6.appendText("\n\tSignal PE per pulse (Ks)");
      textarea6.appendText("\n\tBackground Noise Power (see below)");
      textarea6.appendText("\n\tBackground PE/slot time(Kb)");
      textarea6.appendText("\n\n\tBulk dark current");
      textarea6.appendText("\n\tBulk dark electrons (Kd)");
      textarea6.appendText("\n\tSurface dark current");
      textarea6.appendText("\n\tGain independent surface dark electrons");
      textarea6.appendText("\n\tAmplifier noise equivalent current (NEI)");
      textarea6.appendText("\n\tTemperature");
      textarea6.appendText("\n\tEffective load resistance");
      textarea6.appendText("\n\tGain independent amplifer electrons");
      textarea6.appendText("\n\tOptimum gain");
      textarea6.appendText("\n\tSurface dark electrons (Kds)");
      textarea6.appendText("\n\tAmplifier noise-electrons");
      textarea6.appendText("\n\tExcess noise factor (ENF)");
      textarea6.appendText("\n\tRMS noise electrons (Kn)");
      textarea6.appendText("\n\n\t(1-mer)*Ks/sqrt(2*mer*ENF*Ks+2*Kn)");
      textarea6.appendText("\n\tSQRT(ENF*Ks+Kn)/SQRT(2*mer*ENF*Ks+2*Value of integral in BER eq.)");
      textarea6.appendText("\nBER (M-ary PPM)");
      Panel panel17 = new Panel();
      panel17.setLayout(gridbag1);
      panel17.setBackground(new Color(91,91,255));
      panel17.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel17.setForeground(Color.white);
      constrain(panel17, new Label("Background Radiation"), 0, 15, 1, 1);
      Panel panel18 = new Panel();
      panel18.setLayout(gridbag1);
      TextArea textarea7 = new TextArea(3, 80);
      constrain(panel18, textarea7, 0, 16, 1, 1);
      textarea7.setText("\nRelevant parameters");
      textarea7.appendText("\n\tReceiver area");
      textarea7.appendText("\n\tNet receiver transmission");
      textarea7.appendText("\n\tDetecter FOV");
      textarea7.appendText("\n\tDetecter FOV in solid angle");
      textarea7.appendText("\n\tFilter bandwidth");
      textarea7.appendText("\nStar in FOV");
      textarea7.appendText("\n\tIrradiance");
      textarea7.appendText("\n\tBackground power from star at detector");
      textarea7.appendText("\nPlanet in FOV");
      textarea7.appendText("\n\tReceiver to planet distance");
      textarea7.appendText("\n\tPlanet diameter");
      textarea7.appendText("\n\tAngle subtended by planet at receiver");
      textarea7.appendText("\n\tPlanet radiance");
      textarea7.appendText("\n\tPlanet irradiance");
      textarea7.appendText("\n\tBackground power from planet at detector");
      textarea7.appendText("\n\nSkyCondition");
      textarea7.appendText("\n\tRadiance");
      textarea7.appendText("\n\tPower at detector from scatter");
      textarea7.appendText("\nAverage background power at detector");
      Panel panel19 = new Panel();
      panel19.setLayout(gridbag1);
      panel19.setBackground(new Color(91,91,255));
      panel19.setFont(new Font("Helvetica",Font.ITALIC,11));
      panel19.setForeground(Color.white);
      constrain(panel19, new Label("Footnotes (See manual for more details)"), 0, 16, 1, 1);
      
      Panel panel20 = new Panel();
      panel20.setLayout(gridbag1);
      TextArea textarea8 = new TextArea(3, 80);
      constrain(panel20, textarea8, 0, 17, 1, 1);
      textarea8.setText("\na) \t Beamwidths refer to full width at 1/e^2 point");
      ok = new Button("Ok");
      cancel  = new Button("Cancel");
      Panel panel21 = new Panel();
      panel21.setLayout(gridbag1);
      panel21.setBackground(Color.lightGray);    
      constrain(panel21,cancel,0,18,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
   
      this.setLayout(gridbag1);
      constrain(this, panel1, 0, 0, 1, 1);
      constrain(this, panel2, 0, 1, 1, 1);
      constrain(this, panel3, 0, 3, 1, 1);
      constrain(this, panel4, 0, 4, 1, 1);
      constrain(this, panel5, 0, 2, 1, 1);
      constrain(this, panel6, 0, 5, 1, 1); 
      constrain(this, panel7, 0, 6, 1, 1);
      constrain(this, panel8, 0, 7, 1, 1);
      constrain(this, panel9, 0, 8, 1, 1);
      constrain(this, panel10, 0, 9, 1, 1);
      constrain(this, panel11, 0, 10, 1, 1);
      constrain(this, panel12, 0, 11, 1, 1);
      constrain(this, panel13, 0, 12, 1, 1);
      constrain(this, panel14, 0, 13, 1, 1);
      constrain(this, panel15, 0, 14, 1, 1);
      constrain(this, panel16, 0, 15, 1, 1);
      constrain(this, panel17, 0, 16, 1, 1);
      constrain(this, panel18, 0, 17, 1, 1);
      constrain(this, panel19, 0, 18, 1, 1);
      constrain(this, panel20, 0, 19, 1, 1);
      constrain(this,panel21, 0, 20, 1, 1);
      this.pack();
      this.show();
    }
 public boolean action(Event e,Object arg)
      {
	
	if (e.target== cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
}
  public class r_relay_optics_frame extends Frame
  {
    private Button ok,cancel;
    private Label label2,label3,label4,label5,label6;
   
    private TextField field,truncation,split,redundancy,pointing,optical,spectral,peak;
    private CheckboxGroup b_truncation,b_split,b_redundancy,b_pointing,b_optical;
    private Checkbox[] cb_truncation,cb_split,cb_redundancy,cb_pointing,cb_optical;
    
    
    public r_relay_optics_frame(String title)
      {
	super(title);
	ok= new Button("Ok");
	cancel=new Button("Cancel");
	
	field = new TextField(String.valueOf(Field),10);
	truncation = new TextField(String.valueOf(Truncation),10);
	split= new TextField(String.valueOf(Split),10);
	redundancy = new TextField(String.valueOf(Redundancy),10);
	pointing = new TextField(String.valueOf(Pointing),10);
	optical = new TextField(String.valueOf(Optical),10);
	spectral = new TextField(String.valueOf(Spectral),10);
	peak = new TextField(String.valueOf(Peak),10);
	
	b_truncation = new CheckboxGroup();
	cb_truncation = new Checkbox[2];
	cb_truncation[0] = new Checkbox("%",b_truncation,truncation_units);
	cb_truncation[1] = new Checkbox("dB",b_truncation,!truncation_units);
	
	b_split = new CheckboxGroup();
	cb_split = new Checkbox[2];
	cb_split[0] = new Checkbox("%",b_split,split_units);
	cb_split[1] = new Checkbox("dB",b_split,!split_units);
	
	b_redundancy = new CheckboxGroup();
	cb_redundancy = new Checkbox[2];
	cb_redundancy[0] = new Checkbox("%",b_redundancy,redundancy_units);
	cb_redundancy[1] = new Checkbox("dB",b_redundancy,!redundancy_units);
	b_pointing = new CheckboxGroup();
	cb_pointing = new Checkbox[2];
	cb_pointing[0] = new Checkbox("%",b_pointing,pointing_units);
	cb_pointing[1] = new Checkbox("dB",b_pointing,!pointing_units);
	b_optical = new CheckboxGroup();
	cb_optical = new Checkbox[2];
	cb_optical[0] = new Checkbox("%",b_optical,optical_units);
	cb_optical[1] = new Checkbox("dB",b_optical,!optical_units);
	Panel panel1 = new Panel();
	Panel panel2 = new Panel();
	Panel panel3 = new Panel();
	Panel panel4 = new Panel();
	Panel panel5 = new Panel();
	Panel panel6 = new Panel();
 
	GridBagLayout gridbag = new GridBagLayout();
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	panel5.setLayout(gridbag);
	panel6.setLayout(gridbag);
	this.setLayout(gridbag);
	constrain(panel1,new Label("Detector Field of View"),0,0,1,1);
	constrain(panel1,field,1,0,1,1);
	constrain(panel1,new Label("urad"),2,0,1,1);
	constrain(panel1,new Label("Detector Truncation loss"),0,1,1,1);
	constrain(panel1,truncation,1,1,1,1);
	constrain(panel1,cb_truncation[0],2,1,1,1);
	constrain(panel1,cb_truncation[1],3,1,1,1);
	constrain(panel1,new Label("Acq/Trk Split Loss"),0,2,1,1);
	constrain(panel1,split,1,2,1,1);
	constrain(panel1,cb_split[0],2,2,1,1);
	constrain(panel1,cb_split[1],3,2,1,1);
	constrain(panel1,new Label("Loss due to Redundancy"),0,3,1,1);
	constrain(panel1,redundancy,1,3,1,1);
	constrain(panel1,cb_redundancy[0],2,3,1,1);
	constrain(panel1,cb_redundancy[1],3,3,1,1);
	constrain(panel1,new Label("Pointing Loss"),0,4,1,1);
	constrain(panel1,pointing,1,4,1,1);
	constrain(panel1,cb_pointing[0],2,4,1,1);
	constrain(panel1,cb_pointing[1],3,4,1,1);
	constrain(panel1,new Label("Other Optical Losses"),0,5,1,1);
	constrain(panel1,optical,1,5,1,1);
	constrain(panel1,cb_optical[0],2,5,1,1);
	constrain(panel1,cb_optical[1],3,5,1,1);
	constrain(panel1,new Label("Filter Spectral Bandwidth"),0,6,1,1);
	constrain(panel1,spectral,1,6,1,1);
	constrain(panel1,new Label("nm"),2,6,1,1);
	constrain(panel1,new Label("Peak Filter Transmission"),0,7,1,1);
	constrain(panel1,peak,1,7,1,1);
	constrain(panel1,new Label("percent"),2,7,1,1);
	constrain(panel2,ok,0,0,1,1,0,0,0,10);
	constrain(panel2,cancel,1,0,1,1,0,10,0,0);
	constrain(this,panel1,0,0,1,1);
	constrain(this,panel2,0,1,1,1,20,0,0,0);
	this.pack();
	this.show();
	
	
      }
    public boolean action(Event e,Object arg)
      {
	if(e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if (e.target== cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	
	Field =  (Double.valueOf(field.getText())).doubleValue();
	Truncation =  (Double.valueOf(truncation.getText())).doubleValue();
	Split =  (Double.valueOf(split.getText())).doubleValue();
	Redundancy =  (Double.valueOf(redundancy.getText())).doubleValue();
	Pointing =  (Double.valueOf(pointing.getText())).doubleValue();
	Optical =  (Double.valueOf(optical.getText())).doubleValue();
	Spectral =  (Double.valueOf(spectral.getText())).doubleValue();
	Peak =  (Double.valueOf(peak.getText())).doubleValue();
	truncation_units = cb_truncation[0].getState();
	redundancy_units = cb_redundancy[0].getState();
	split_units = cb_split[0].getState();
	pointing_units = cb_pointing[0].getState();
	optical_units = cb_optical[0].getState();
      }
  
    
  }
  
  public class detector_frame extends Frame
  {
    private Button ok,cancel;
    private Label dtype,label2,label3,label4,label5,label6;
    private Choice detector;
    private TextField quantum,bulkdark,surfacedark,risefall,diameter,capacitance,gain,ionization;
    private Panel panel4 = new Panel();
    private Panel panel5 = new Panel();
    private GridBagLayout gridbag = new GridBagLayout();
    public detector_frame(String title)
      {
	super(title);
	
	ok = new Button("Ok");
	cancel  = new Button("Cancel");
	
	detector = new Choice();
	detector.addItem("Bialkali PMT (Burle 4516)");
	detector.addItem("Multialkali PMT (Burle 8644)");
	detector.addItem("ERMA PMT (Burle C7164R)");
	detector.addItem("GaAs PMT (Burle C31034A)");
	detector.addItem("EG&G SLiK APD");
	detector.addItem("Si APD (EG&G C30902S)");
	detector.addItem("Si APD (EG&G C30817)");
	detector.addItem("Si APD IR Enhanced (EG&G C30954E)");
	detector.addItem("Si APD IR Enhanced (EG&G C30955E)");
	detector.addItem("Si APD IR Enhanced (EG&G C30956E)");
	detector.addItem("Si APD (Hamamatsu S2383)");
	detector.addItem("InGaAs APD (EG&G C30662EBL)");
	detector.addItem("Si PIN PD (Hamamatsu S4751)");
	detector.addItem("InGaAs PIN PD (EG&G C30641)");
	detector.select(Detector);
	
	quantum = new TextField(String.valueOf(Quantum),10);
	bulkdark = new TextField(String.valueOf(BulkDark),10);
	surfacedark = new TextField(String.valueOf(SurfaceDark),10);
	risefall = new TextField(String.valueOf(RiseFall),10);
	diameter = new TextField(String.valueOf(DetectorDiameter),10);
	capacitance = new TextField(String.valueOf(Capacitance),10);
	gain = new TextField(String.valueOf(Gain),10);
	ionization = new TextField(String.valueOf(Ionization),10);
	int temp = detector.getSelectedIndex();
	if ((temp >=0) && (temp <4))
	  {
	    dtype = new Label("PMT");
	  }
	else if((temp >=4)&&(temp <12))
	  {
	    dtype = new Label("APD");
	  }
	else dtype = new Label("PD");
	Panel panel1 = new Panel();
	Panel panel2 = new Panel();
	Panel panel3 = new Panel();
	Panel panel6 = new Panel();
	
 
	
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	panel5.setLayout(gridbag);
	panel6.setLayout(gridbag);
	this.setLayout(gridbag);
	constrain(panel1,new Label("Name: "),0,0,1,1);
	constrain(panel1,detector,1,0,1,1);
	label2 = new Label("Detector Type");
	label2.setFont(new Font("Helvetica",Font.BOLD,14));
	constrain(panel2,label2,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,dtype,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	
	constrain(panel3,new Label("Quantum Efficiency"),0,0,1,1);
	constrain(panel3,quantum,1,0,1,1);
	constrain(panel3,new Label("Bulk Dark Current (pA)"),0,1,1,1);
	constrain(panel3,bulkdark,1,1,1,1);
	constrain(panel3,new Label("Surface Dark Current (pA)"),0,2,1,1);
	constrain(panel3,surfacedark,1,2,1,1);
	constrain(panel3,new Label("10 - 90% Rise/Fall Time (ns)"),0,3,1,1);
	constrain(panel3,risefall,1,3,1,1);
	constrain(panel3,new Label("Detector Diameter (mm)"),0,4,1,1);
	constrain(panel3,diameter,1,4,1,1);
	constrain(panel3,new Label("Detector Capacitance (F)"),0,5,1,1);
	constrain(panel3,capacitance,1,5,1,1);
       
	constrain(panel4,new Label("Maximum Recommended Gain"),0,0,1,1);
	constrain(panel4,gain,1,0,1,1);
	constrain(panel5,new Label("Ionization Rate Ratio"),0,0,1,1);
	constrain(panel5,ionization,1,0,1,1);
	
	constrain(panel6,ok,0,0,1,1,0,10,0,0);
	constrain(panel6,cancel,1,0,1,1,0,0,0,10);
	
	constrain(this,panel1,0,0,1,1);
	constrain(this,panel2,0,1,1,1,0,0,20,0);
	constrain(this,panel3,0,2,1,1);
       
	if ((temp >=0) && (temp <4))
	  {
	    constrain(this,panel4,0,3,1,1);
	  }
	else if((temp >=4)&&(temp <12))
	  {
	    constrain(this,panel4,0,3,1,1);
	    constrain(this,panel5,0,4,1,1);
	  }
	else dtype = new Label("PD");
	 
	    
	    
	  
	
	constrain(this,panel6,0,5,1,1,15,0,0,0);
	this.pack();
	this.show();
      }
    public boolean action(Event e,Object arg)
      {
	if(e.target == detector)
	  {
	   
	   try{getinfo();}
	    catch(IOException eez){}
	    int temp = detector.getSelectedIndex();
	    if ((temp >=0) && (temp <4))
	      {
		dtype.setText("PMT");
		detectorTYPE = "PMT";
		this.remove(panel4);
		this.remove(panel5);
		constrain(this,panel4,0,3,1,1);
		this.pack();
		
	      }
	    else if((temp >=4)&&(temp <12))
	      {
		dtype.setText("APD");
		detectorTYPE = "APD";
		constrain(this,panel4,0,3,1,1);
		constrain(this,panel5,0,4,1,1);
		this.pack();
		
	      }
	    else
	      {
		dtype.setText("PD");
		detectorTYPE = "PD";
		this.remove(panel4);
		this.remove(panel5);
		this.pack();
	      }
	    
	    return true;
	  }
	else if(e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if (e.target==cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	Detector = detector.getSelectedItem();
	t_detector.setText(Detector);
	t_detector.setAlignment(t_detector.CENTER);
	Quantum = (Double.valueOf(quantum.getText())).doubleValue();
	BulkDark = (Double.valueOf(bulkdark.getText())).doubleValue();
	SurfaceDark = (Double.valueOf(surfacedark.getText())).doubleValue();
	RiseFall = (Double.valueOf(risefall.getText())).doubleValue();
	DetectorDiameter=(Double.valueOf(diameter.getText())).doubleValue();
	Capacitance=(Double.valueOf(capacitance.getText())).doubleValue();
	Gain=(Double.valueOf(gain.getText())).doubleValue();
	Ionization=(Double.valueOf(ionization.getText())).doubleValue();
	detectorTYPE = dtype.getText();
	
      }
    public void getinfo() throws IOException
      {
	 String filename = new String(detector.getSelectedItem());
	 filename = filename.replace('(','_');
	 filename = filename.replace(' ','_');
	 filename = filename.replace(')','_');
	 filename = filename.replace('-','_');
	 
	 URL url = new URL("http://www331.jpl.nasa.gov/group1/focas_birju/detectors/"+filename);
	 URLConnection connection = url.openConnection();
	 connection.connect();
	 
	 DataInputStream in = new DataInputStream(connection.getInputStream());
	 detectorTYPE = in.readLine();
	 ionization.setText(in.readLine());
	 gain.setText(in.readLine());
	 bulkdark.setText(in.readLine());
	 surfacedark.setText(in.readLine());
	 risefall.setText(in.readLine());
	 diameter.setText(in.readLine());
	 capacitance.setText(in.readLine());
	 
	 filename = filename + "QE";
	 System.out.println(filename);
	 URL url2 = new URL("http://www331.jpl.nasa.gov/group1/focas_birju/detectors/QE/"+filename);
	 URLConnection connection2 = url2.openConnection();
	 connection2.connect();
	 DataInputStream in2 = new DataInputStream(connection2.getInputStream());
	 double QE,QE2,ans;
	 int top=0,bot=75,i;
	 if((LaserWavelength*1.0e9)>=2000)
	   {
	     top=bot;
	     for(i=0;i<top;i++) in2.readLine();
	     QE = (Double.valueOf(in2.readLine())).doubleValue();
	     QE2 = QE;
	   
	   }
	 else
	   {
	     while(bot-top != 1)
	       {
		 i = (int)((bot-top)/2) + top;
		 if((LaserWavelength*1.0E9) <= QE_wavelengths[i]) bot = i;
		 else top =i;     
	       }
	     if((LaserWavelength*1.0E9)==QE_wavelengths[bot]) top=bot;
	     for(i=0;i<top;i++) in2.readLine();
	     QE = (Double.valueOf(in2.readLine())).doubleValue();
	     QE2 =  (Double.valueOf(in2.readLine())).doubleValue();
	   }
	 ans = QE + ((LaserWavelength*1.0E9) - QE_wavelengths[top])*(QE2-QE)/20.0;
	 quantum.setText(String.valueOf((float)ans));
      }
    
  }
  public class noise_sources_frame extends Frame
  {
    private Button ok,cancel;
    private Label label1,label2,label3,label4,label5,label6;
    private Choice conditions,planets,stars;
    private TextField distance;
    public noise_sources_frame(String title)
      {
	super(title);
	ok = new Button("Ok");
	cancel  = new Button("Cancel");
	label1 = new Label("Radiant Sources in Field-Of-View");
	label1.setFont(new Font("Helvetica",Font.BOLD,14));
	distance = new TextField(String.valueOf(Distance),10);
	label2 = new Label(String.valueOf(LaserWavelength*1E9));
	
	conditions = new Choice();
	conditions.addItem("Dark");
	conditions.addItem("Cloudy");
	conditions.addItem("Night");
	conditions.addItem("Sunny1");
	conditions.addItem("Sunny2");
	conditions.select(Conditions);
	
	planets = new Choice();
	planets.addItem("None");
	planets.addItem("Earth");
	planets.addItem("Jupiter");
	planets.addItem("Mars");
	planets.addItem("Moon");
	planets.addItem("Neptune");
	planets.addItem("Pluto");
	planets.addItem("Saturn");
	planets.addItem("Uranus");
	planets.addItem("Venus");
	planets.select(Planets);
	stars = new Choice();
	stars.addItem("None");
	stars.addItem("Achemar");
	stars.addItem("Aldebaron");
	stars.addItem("Altair");
	stars.addItem("Arcturus");
	stars.addItem("Betelguese");
	stars.addItem("Canopus");
	stars.addItem("Capella");
	stars.addItem("Deneb");
	stars.addItem("Fomalhault");
	stars.addItem("Hader");
	stars.addItem("Mimosa");
	stars.addItem("Pollux");
	stars.addItem("Procyon");
	stars.addItem("Rigel");
	stars.addItem("Rigel Kent");
	stars.addItem("Sirius");
	stars.addItem("Spica");
	stars.addItem("Vega");
	stars.select(Stars);
	Panel panel1 = new Panel();
	Panel panel2 = new Panel();
	Panel panel3 = new Panel();
	Panel panel4 = new Panel();
	Panel panel5 = new Panel();
	Panel panel6 = new Panel();
 
	GridBagLayout gridbag = new GridBagLayout();
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	panel5.setLayout(gridbag);
	panel6.setLayout(gridbag);
	this.setLayout(gridbag);
	
	constrain(panel1,new Label("Sky Conditions:"),0,0,1,1);
	constrain(panel1,conditions,1,0,1,1);
	
	constrain(panel2,label1,0,0,1,1);
	constrain(panel3,new Label("Planets:"),0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,0,0,0);
	constrain(panel3,planets,1,0,1,1);
	constrain(panel3,new Label("Stars:"),0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,0,0,0);
	constrain(panel3,stars,1,1,1,1);
	constrain(panel4,new Label("Current transmitter wavelength = "),0,0,1,1);
	constrain(panel4,label2,1,0,1,1);
	constrain(panel4,new Label("nm"),2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel5,new Label("Specify distance from planet to"),0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.SOUTH,0.0,0.0,0,0,0,10);
	constrain(panel5,new Label("reciever calculate angle subtended"),0,1,1,1);
	constrain(panel5,distance,1,1,1,1);
	constrain(panel5,new Label("km"),2,1,1,1);
	
	constrain(panel6,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,10);
	constrain(panel6,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,0);
	constrain(this,panel1,0,0,1,1);
	constrain(this,panel2,0,1,1,1);
	constrain(this,panel3,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,20,10,0);
	constrain(this,panel4,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,10,10,0,0);
	constrain(this,panel5,0,4,1,1);
	constrain(this,panel6,0,5,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,20,0,0,0);
	this.pack();
	this.show();
	
      }
    public boolean action(Event e,Object arg)
      {
	if(e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	
	Stars = stars.getSelectedItem();
	Planets = planets.getSelectedItem();
	Conditions = conditions.getSelectedItem();
	Distance =  (Double.valueOf(distance.getText())).doubleValue();
      }
  }
  public class atmosphere_frame extends Frame
  {
    private Button ok,cancel;
    private Label label1,label2,label3,label4,label5,label6;
    private TextField seeing,trans,angle;
    CheckboxGroup b_seeing,b_trans;
    Checkbox[] cb_seeing,cb_trans;
    
    
    public atmosphere_frame(String title)
      {
	super(title);
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	seeing = new TextField(String.valueOf(Seeing),10);
	trans  = new TextField(String.valueOf(Trans),10);
	angle = new TextField(String.valueOf(Angle),10);
	
	b_seeing  = new CheckboxGroup();
	cb_seeing = new Checkbox[2];
	cb_seeing[0] = new Checkbox("arcsec",b_seeing,Seeing_units);
	cb_seeing[1] = new Checkbox("urad",b_seeing,!Seeing_units);
	
	b_trans = new CheckboxGroup();
	cb_trans = new Checkbox[1];
	cb_trans[0] = new Checkbox("use default values",b_trans,usedefault);
	
	
	Panel panel1 = new Panel();
	Panel panel2 = new Panel();
	Panel panel3 = new Panel();
	Panel panel4 = new Panel();
	Panel panel5 = new Panel();
	Panel panel6 = new Panel();
 
	GridBagLayout gridbag = new GridBagLayout();
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	panel5.setLayout(gridbag);
	panel6.setLayout(gridbag);
	this.setLayout(gridbag);
	constrain(panel1,new Label("Atmospheric Transmission: 0 to "),0,0,1,1);
	constrain(panel1,trans,1,0,1,1);
	constrain(panel1,new Label("(at zenith)"),2,0,1,1);
	constrain(panel1,cb_trans[0],1,1,1,1);
	
	constrain(panel2,new Label("Observation Angle:"),0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,0,0,0);
	constrain(panel2,angle,1,0,1,1,0,10,0,0);
	constrain(panel2,new Label("degrees from zenith"),2,0,1,1);
	
	constrain(panel3,new Label("Atmospheric Seeing:"),0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,0,0,0);
	constrain(panel3,seeing,1,0,1,1);
	constrain(panel3,cb_seeing[0],2,0,1,1);
	constrain(panel3,cb_seeing[1],3,0,1,1);
	constrain(panel4,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,10);
	constrain(panel4,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,0);
	constrain(this,panel1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,10,0);
	constrain(this,panel2,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,10,0,10,0);
	constrain(this,panel3,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,10,0);
	constrain(this,panel4,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,10,0,0,0);
	
	this.pack();
	this.show();
		  
      }
    public boolean action(Event e,Object arg)
      {
	if(e.target==ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	Trans =  (Double.valueOf(trans.getText())).doubleValue();
	Angle =  (Double.valueOf(angle.getText())).doubleValue();
	Seeing =  (Double.valueOf(seeing.getText())).doubleValue();
	Seeing_units = cb_seeing[0].getState();
	usedefault = cb_trans[0].getState();
      }
  }
  public class pointing_frame extends Frame
  {
    private Button ok,cancel;
    private Label label1,label2,label3,label4,label5,label6;
    TextField t_offset,t_jitter;
    CheckboxGroup b_offset,b_jitter;
    Checkbox[] cb_offset,cb_jitter;
    
    public pointing_frame(String title)
      {
	super(title);
	
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	
	Panel panel1,panel2,panel3,panel4,panel5,panel6;
	panel1 = new Panel();
	panel2 = new Panel();
	panel3 = new Panel();
	panel4 = new Panel();
	panel5 = new Panel();
	panel6 = new Panel();
	GridBagLayout gridbag = new GridBagLayout();
	this.setLayout(gridbag);
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	panel5.setLayout(gridbag);
	panel6.setLayout(gridbag);
	label1 = new Label("Current Transmitter Beamwidth: ");
	label2 = new Label(String.valueOf(PointingBeamwidth));
	label3 = new Label("Pointing Offset: ");
	label4 = new Label("Single axis RMS");
	label5 = new Label("Pointing Jitter: ");
	
	t_offset = new TextField(String.valueOf(PointingOffset),10);
	t_jitter = new TextField(String.valueOf(PointingJitter),10);
	b_offset = new CheckboxGroup();
	b_jitter = new CheckboxGroup();
	cb_offset = new Checkbox[2];
	cb_jitter = new Checkbox[2];
	cb_offset[0]  = new Checkbox("urad",b_offset,PointingOffset_units);
	cb_offset[1] = new Checkbox("% of Beamwidth",b_offset,!PointingOffset_units);
	cb_jitter[0] = new Checkbox("urad",b_jitter,PointingJitter_units);
	cb_jitter[1] = new Checkbox("% of Beamwidth",b_jitter,!PointingJitter_units);
	constrain(panel1,label1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel1,label2,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,panel1,0,0,1,1);
	constrain(panel3,label3,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel3,t_offset,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel3,cb_offset[0],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel3,cb_offset[1],3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel4,label4,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,0,0,0);
	constrain(panel4,label5,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHEAST,0.0,0.0,0,0,0,0);
	constrain(panel4,t_jitter,1,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel4,cb_jitter[0],2,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel4,cb_jitter[1],3,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel5,panel4,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,0,0,0);
	constrain(panel6,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,10);
	constrain(panel6,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,0);
	constrain(this,panel2,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel3,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel5,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel6,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	
	this.pack();
	this.show();
      }
  public boolean action(Event e,Object arg)
      {
	if(e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	    
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
	
    public void update()
      {
	PointingOffset =  (Double.valueOf(t_offset.getText())).doubleValue();
	PointingJitter =  (Double.valueOf(t_jitter.getText())).doubleValue();
	PointingOffset_units = cb_offset[0].getState();
	PointingJitter_units = cb_jitter[0].getState();
	//PointingBeamwidth = ?
      }
  }
  public class telescope_r_frame extends Frame
  {
    
    private Button ok,cancel,def;
    private Label name,aperture,secondary,teleloss,surface,profile,width,inspace,des;
    private Choice c_name;
    private CheckboxGroup b_aperture,b_secondary,b_teleloss,b_surface,b_profile,b_inspace;
    private Checkbox[] cb_aperture,cb_secondary,cb_teleloss,cb_surface,cb_profile,cb_inspace;
    private TextField t_aperture,t_secondary,t_teleloss,t_surface,t_width;
    public telescope_r_frame(String title)
      {
	super(title);
	
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	def = new Button("Default");
	name = new Label("Name: ");
	aperture = new Label("Primary Aperture");
	secondary = new Label("Secondary Obsuration: ");
	teleloss = new Label("Telescope Optical Losses: ");
	
	des = new Label("urad");
	des.setFont(new Font("Helvetica",Font.PLAIN,12));
	inspace = new Label("Usable in Space? ");
	c_name = new Choice();
	c_name.addItem("X2000");
	c_name.addItem("OCD");
	c_name.addItem("LCE on ETS-VI");
	c_name.addItem("TMF 24-inch");
	c_name.addItem("TMF 48-inch");
	c_name.addItem("1-m telescope");
	c_name.addItem("10-m telescope");
	c_name.select(R_TelescopeName);
	b_aperture = new CheckboxGroup();
	b_secondary = new CheckboxGroup();
	b_teleloss = new CheckboxGroup();
	
	b_inspace = new CheckboxGroup();
	
	cb_aperture = new Checkbox[2];
	cb_aperture[0] = new Checkbox("cm",b_aperture,R_Aperture_units);
	cb_aperture[1]  = new Checkbox("m",b_aperture,!R_Aperture_units);
	
	cb_secondary = new Checkbox[2];
	cb_secondary[0] = new Checkbox("cm",b_secondary,R_Secondary_units);
	cb_secondary[1] = new Checkbox("% of Diameter",b_secondary,!R_Secondary_units);
	
	cb_teleloss = new Checkbox[2];
	cb_teleloss[0] = new Checkbox("dB loss",b_teleloss,R_TelescopeLosses_units);
	cb_teleloss[1] = new Checkbox("% loss",b_teleloss,!R_TelescopeLosses_units);
	
	
	
	cb_inspace = new Checkbox[2];
	cb_inspace[0] = new Checkbox("yes",b_inspace,R_inSpace);
	cb_inspace[1] = new Checkbox("no",b_inspace,!R_inSpace);
	t_aperture = new TextField(String.valueOf(R_ApertureDiameter),10);
	t_secondary = new TextField(String.valueOf(R_SecondaryObsuration),10);
	t_teleloss = new TextField(String.valueOf(R_TelescopeLosses),10);
	
	GridBagLayout gridbag = new GridBagLayout();
	this.setLayout(gridbag);
	Panel panel1,panel2,panel3;
	panel1 = new Panel();
	panel1.setLayout(gridbag);
	
	panel2  = new Panel();
	panel2.setLayout(gridbag);
	
	panel3 = new Panel();
	panel3.setLayout(gridbag);
	
	
	constrain(panel1,name,0,0,1,1);
	constrain(panel1,c_name,1,0,1,1);
	constrain(panel2,aperture,0,0,1,1);
	constrain(panel2,t_aperture,1,0,1,1);
	constrain(panel2,cb_aperture[0],2,0,1,1);
	constrain(panel2,cb_aperture[1],3,0,1,1);
	constrain(panel2,secondary,0,1,1,1);
	constrain(panel2,t_secondary,1,1,1,1);
	constrain(panel2,cb_secondary[0],2,1,1,1);
	constrain(panel2,cb_secondary[1],3,1,1,1);
	constrain(panel2,teleloss,0,2,1,1);
	constrain(panel2,t_teleloss,1,2,1,1);
	constrain(panel2,cb_teleloss[0],2,2,1,1);
	constrain(panel2,cb_teleloss[1],3,2,1,1);
	constrain(panel2,inspace,0,3,1,1);
	constrain(panel2,cb_inspace[0],1,3,1,1);
	constrain(panel2,cb_inspace[1],2,3,1,1);
	constrain(panel3,ok,0,0,1,1,0,0,0,10);
	constrain(panel3,cancel,1,0,1,1,0,10,0,0);
	
	constrain(this,panel1,0,0,1,1);
	constrain(this,panel2,0,1,1,1);
	constrain(this,panel3,0,2,1,1,20,0,0,0);
	this.pack();
	this.show();
      
      }
     public boolean action(Event e,Object arg)
      {
	if (e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return false;
	  }
	
	else return false;
      }
   
    
    public void update()
      {
	
	R_TelescopeName = c_name.getSelectedItem();
	R_ApertureDiameter =  (Double.valueOf(t_aperture.getText())).doubleValue();
	R_SecondaryObsuration = (Double.valueOf(t_secondary.getText())).doubleValue();
	R_TelescopeLosses = (Double.valueOf(t_teleloss.getText())).doubleValue();
	
	R_Aperture_units = cb_aperture[0].getState();
	R_Secondary_units = cb_secondary[0].getState();
	R_TelescopeLosses_units = cb_teleloss[0].getState();
	
	R_inSpace = cb_inspace[0].getState();
	t_telescope_r.setText(R_TelescopeName);
	t_telescope_r.setAlignment(t_telescope_r.CENTER);
      }
public void getinfo() throws IOException
      {
	String filename = new String(c_name.getSelectedItem());
	filename = filename.replace(' ','_');
	filename = filename.concat(".txt");
	
	URL url = new URL("http://www331.jpl.nasa.gov/group1/focas_birju/t_telescope/"+filename);
	URLConnection connection = url.openConnection();
	connection.connect();
	
	DataInputStream in = new DataInputStream(connection.getInputStream());
	double temp;
	temp =  (Double.valueOf(in.readLine())).doubleValue();
	t_aperture.setText(String.valueOf(temp*100));
	temp =  (Double.valueOf(in.readLine())).doubleValue();
	t_secondary.setText(String.valueOf(temp*100));
	b_secondary.setCurrent(cb_secondary[1]);
	b_aperture.setCurrent(cb_aperture[0]);
	b_teleloss.setCurrent(cb_teleloss[1]);
	RxSurfErr=(Double.valueOf(in.readLine())).doubleValue(); //RMS
	
	RxLossTO = (Double.valueOf(in.readLine())).doubleValue();
      
	RxLossSS=(Double.valueOf(in.readLine())).doubleValue();
	String temp1 = new String(in.readLine());
	
	if (temp1.equals("Yes")){
	  b_inspace.setCurrent(cb_inspace[0]);
	  cb_inspace[0].setState(true);
	 
	}
	else b_inspace.setCurrent(cb_inspace[1]);
	
	
	
      }
  }
  
  public class telescope_t_frame extends Frame
  {
    private Button ok,cancel,def;
    private Label name,aperture,secondary,teleloss,surface,profile,width,inspace,des;
    private Choice c_name;
    private CheckboxGroup b_aperture,b_secondary,b_teleloss,b_surface,b_profile,b_inspace;
    private Checkbox[] cb_aperture,cb_secondary,cb_teleloss,cb_surface,cb_profile,cb_inspace;
    private TextField t_aperture,t_secondary,t_teleloss,t_surface,t_width;
    public telescope_t_frame(String title)
      {
	super(title);
	
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	def = new Button("Default");
	name = new Label("Name: ");
	aperture = new Label("Aperture Diameter: ");
	secondary = new Label("Secondary Obsuration: ");
	teleloss = new Label("Telescope Optical Losses: ");
	surface = new Label("Surface Quality");
	profile = new Label("Beam Profile");
	width = new Label("Beam Width");
	des = new Label("urad");
	des.setFont(new Font("Helvetica",Font.PLAIN,12));
	inspace = new Label("Usable in Space? ");
	c_name = new Choice();
	c_name.addItem("X2000");
	c_name.addItem("OCD");
	c_name.addItem("LCE on ETS-VI");
	c_name.addItem("TMF 24-inch");
	c_name.addItem("TMF 48-inch");
	c_name.addItem("1-m telescope");
	c_name.addItem("10-m telescope");
	c_name.select(T_TelescopeName);
	b_aperture = new CheckboxGroup();
	b_secondary = new CheckboxGroup();
	b_teleloss = new CheckboxGroup();
	b_surface = new CheckboxGroup();
	b_profile = new CheckboxGroup();
	b_inspace = new CheckboxGroup();
	
	cb_aperture = new Checkbox[2];
	cb_aperture[0] = new Checkbox("cm",b_aperture,Aperture_units);
	cb_aperture[1]  = new Checkbox("m",b_aperture,!Aperture_units);
	
	cb_secondary = new Checkbox[2];
	cb_secondary[0] = new Checkbox("cm",b_secondary,Secondary_units);
	cb_secondary[1] = new Checkbox("% of Diameter",b_secondary,!Secondary_units);
	
	cb_teleloss = new Checkbox[2];
	cb_teleloss[0] = new Checkbox("dB loss",b_teleloss,TelescopeLosses_units);
	cb_teleloss[1] = new Checkbox("% loss",b_teleloss,!TelescopeLosses_units);
	
	cb_surface = new Checkbox[2];
	cb_surface[0] = new Checkbox("Strehl Ratio",b_surface,Surface_units);
	cb_surface[1] = new Checkbox("RMS Surface Error",b_surface, !Surface_units);
	
	cb_profile = new Checkbox[2];
	cb_profile[0] = new Checkbox("Airy",b_profile,BeamProfile);
	cb_profile[1] = new Checkbox("Gaussian",b_profile,!BeamProfile);
	cb_inspace = new Checkbox[2];
	cb_inspace[0] = new Checkbox("yes",b_inspace,inSpace);
	cb_inspace[1] = new Checkbox("no",b_inspace,!inSpace);
	if(Secondary_units)
	  {
	   
	   t_secondary = new TextField(String.valueOf(SecondaryObsuration*100.0),10);
	   
	  }
	else
	  {
	    t_secondary = new TextField(String.valueOf((SecondaryObsuration/ApertureDiameter)*100.0),10);
	  }
	if(Aperture_units)
	  {
	    t_aperture = new TextField(String.valueOf(ApertureDiameter*100),10);
	  }
	else t_aperture = new TextField(String.valueOf(ApertureDiameter),10);
      
	  
	t_teleloss = new TextField(String.valueOf(TelescopeLosses),10);
	t_surface = new TextField(String.valueOf(Surface_Quality),10);
	t_width = new TextField(String.valueOf(BeamWidth),10);
	GridBagLayout gridbag = new GridBagLayout();
	this.setLayout(gridbag);
	Panel panel1,panel2,panel3,panel4,panel6;
	panel1 = new Panel();
	panel1.setLayout(gridbag);
	
	panel2  = new Panel();
	panel2.setLayout(gridbag);
	
	panel3 = new Panel();
	panel3.setLayout(gridbag);
	
	panel4 = new Panel();
	panel4.setLayout(gridbag);
	
	Panel panel5 = new Panel();
	panel5.setLayout(gridbag);
	panel6 = new Panel();
	panel6.setLayout(gridbag);
	Panel sp = new Panel();
	sp.setLayout(gridbag);
	
	constrain(panel1,name,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,5,0,0,0);
	constrain(panel1,aperture,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,28,0,0,0);
	constrain(panel1,secondary,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,26,0,15,0);
	constrain(panel1,teleloss,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,12,0,10,0);
	constrain(panel1,surface,0,4,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,17,0,10,0);
	
	
	constrain(panel2,c_name,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,5,0,10,0);
	constrain(panel2,t_aperture,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,10,0,10,0);
	constrain(panel2,t_secondary,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,10,0,10,0);
	constrain(panel2,t_teleloss,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,10,0,10,0);
	constrain(panel2,t_surface,0,4,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,10,0,10,0);
	constrain(panel2,cb_aperture[0],1,1,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_aperture[1],2,1,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_secondary[0],1,2,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_secondary[1],2,2,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_teleloss[0],1,3,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_teleloss[1],2,3,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_surface[0],1,4,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_surface[1],2,4,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,des,1,6,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel3,profile,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,83,0,0);
	constrain(panel3,cb_profile[0],1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel3,cb_profile[1],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel4,width,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,83,0,0);
	constrain(panel4,t_width,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel4,des,2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(sp,inspace,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,83,0,0);
	constrain(sp,cb_inspace[0],1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(sp,cb_inspace[1],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	
	constrain(panel5,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,20);
	constrain(panel5,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,10);
	constrain(panel5,def,2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,0);
	
	constrain(panel6,panel1,0,0,1,1);
	constrain(panel6,panel2,1,0,1,1);
	constrain(this,panel6,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.0,0.0,0,0,0,0);
	constrain(this,panel3,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.0,0.0,10,0,10,0);
	constrain(this,panel4,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.0,0.0,10,0,10,0);
	constrain(this,sp,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.0,0.0,10,0,10,0);
	constrain(this,panel5,0,4,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	this.pack();
	this.show();
      }
    public boolean action(Event e,Object arg)
      {
	if (e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return false;
	  }
	else if(e.target == def)
	  {
	    try{getinfo();}
	    catch(IOException ep){}
	    return true;
	  }
	else if(e.target==c_name)
	  {
	    try{getinfo();}
	    catch(IOException ep){}
	    return true;
	  }
	else return false;
      }
   
    
    public void update()
      {
	double temp;
	T_TelescopeName = c_name.getSelectedItem();
	temp =  (Double.valueOf(t_aperture.getText())).doubleValue();
	
	Aperture_units = cb_aperture[0].getState();
	if(Aperture_units) ApertureDiameter = temp/100.0;
	else ApertureDiameter = temp;
       
	temp = (Double.valueOf(t_secondary.getText())).doubleValue();
	Secondary_units = cb_secondary[0].getState();
	if(Secondary_units) temp = SecondaryObsuration/100.0;
	else SecondaryObsuration=(temp/100.0)*ApertureDiameter;
	
	TelescopeLosses = (Double.valueOf(t_teleloss.getText())).doubleValue();
	Surface_Quality = (Double.valueOf(t_surface.getText())).doubleValue();
	BeamWidth = (Double.valueOf(t_width.getText())).doubleValue();
	
	
	TelescopeLosses_units = cb_teleloss[0].getState();
	Surface_units = cb_surface[0].getState();
	BeamProfile = cb_profile[0].getState();
	inSpace = cb_inspace[0].getState();
	t_telescope_t.setText(T_TelescopeName);
	t_telescope_t.setAlignment(t_telescope_t.CENTER);
      }
    public void getinfo() throws IOException
      {
	String filename = new String(c_name.getSelectedItem());
	filename = filename.replace(' ','_');
	filename = filename.concat(".txt");
	
	URL url = new URL("http://www331.jpl.nasa.gov/group1/focas_birju/t_telescope/"+filename);
	URLConnection connection = url.openConnection();
	connection.connect();
	
	DataInputStream in = new DataInputStream(connection.getInputStream());
	double temp;
	temp =  (Double.valueOf(in.readLine())).doubleValue();
	t_aperture.setText(String.valueOf(temp*100));
	temp =  (Double.valueOf(in.readLine())).doubleValue();
	t_secondary.setText(String.valueOf(temp*100));
	b_secondary.setCurrent(cb_secondary[1]);
	b_aperture.setCurrent(cb_aperture[0]);
	b_teleloss.setCurrent(cb_teleloss[1]);
	t_surface.setText(in.readLine());
	b_surface.setCurrent(cb_surface[1]);
	in.readLine();
	in.readLine();
	String temp1 = new String(in.readLine());
	
	if (temp1.equals("Yes")){
	  b_inspace.setCurrent(cb_inspace[0]);
	  cb_inspace[0].setState(true);
	 
	}
	else b_inspace.setCurrent(cb_inspace[1]);
	
	temp1 =in.readLine(); 
	if(temp1.equals("Airy")) b_profile.setCurrent(cb_profile[0]);
	else b_profile.setCurrent(cb_profile[1]);
	
	
	
      }
	
  }
  public class laser_frame extends Frame
  {
    private Button ok,cancel;
    Label name,type,wavelength,power,spectral,pulse;
    Choice c_names;
    CheckboxGroup b_laser,b_wave,b_power,b_spectral;
    Checkbox[] cb_laser,cb_wave,cb_power,cb_spectral;
    TextField t_wave,t_power,t_spectral,t_pulse;
    private Button def = new Button("Default");
    public laser_frame(String title)
      {
	super(title);
	
	
	Panel panel1,panel2,panel3,panel4,panel5,panel6,panel7;
	panel1 = new Panel();
	panel2 = new Panel();
	panel3 = new Panel();
	panel4 = new Panel();
	panel5 = new Panel();
	panel6 = new Panel();
	panel7 = new Panel();
	name = new Label("Name: ");
	type = new Label("Laser Type");
	wavelength = new Label("Wavelength: ");
	power = new Label("Average Power: ");
	spectral = new Label("Spectral Width: ");
	pulse = new Label("Pulse Width(ns): ");
	name.setAlignment(name.LEFT);
	type.setAlignment(type.LEFT);
	wavelength.setAlignment(wavelength.LEFT);
	power.setAlignment(power.LEFT);
	spectral.setAlignment(spectral.LEFT);
	pulse.setAlignment(pulse.LEFT);
	
	c_names = new Choice();
	c_names.addItem("Q-switched ND:YAG");
	c_names.addItem("Q-switched Doubled ND:YAG");
	c_names.addItem("ND:YAG");
	c_names.addItem("Doubled ND:YAG");
	c_names.addItem("Hytec");
	c_names.addItem("LD:830");
	c_names.addItem("LD:860");
	c_names.addItem("LD:900");
	c_names.select(LaserName);
	b_laser = new CheckboxGroup();
	b_wave = new CheckboxGroup();
	b_power = new CheckboxGroup();
	b_spectral = new CheckboxGroup();
	
	cb_laser = new Checkbox[2];
	cb_laser[0] = new Checkbox("CW",b_laser,LaserType);
	cb_laser[1] = new Checkbox("Pulsed",b_laser,!LaserType);
	cb_wave = new Checkbox[2];
	cb_wave[0] = new Checkbox("nm",b_wave,Wavelength_units);
	cb_wave[1] = new Checkbox("um",b_wave,!Wavelength_units);
	
	cb_power = new Checkbox[2];
	cb_power[0] = new Checkbox("mW",b_power,Power_units);
	cb_power[1] = new Checkbox("W",b_power,!Power_units);
	
	cb_spectral = new Checkbox[2];
	cb_spectral[0] = new Checkbox("=",b_spectral,Spectral_units);
	cb_spectral[1] = new Checkbox("nm",b_spectral,!Spectral_units);
	if(Wavelength_units) t_wave = new TextField(String.valueOf(LaserWavelength*1E9),10);
	else t_wave = new TextField(String.valueOf(LaserWavelength/1E-6),10);
	if(Power_units) t_power = new TextField(String.valueOf(LaserAvgPower*1000),10);
	else  t_power = new TextField(String.valueOf(LaserAvgPower),10);
	t_spectral = new TextField(String.valueOf(LaserSpectralWidth),10);
	t_pulse = new TextField(String.valueOf(LaserPulseWidth),10);
	
	
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	
	GridBagLayout gridbag = new GridBagLayout();
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	panel5.setLayout(gridbag);
	panel6.setLayout(gridbag);
	panel7.setLayout(gridbag);
	this.setLayout(gridbag);
	constrain(panel1,name,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel1,c_names,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,type,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_laser[0],1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_laser[1],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel3,wavelength,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,2,0,0);
	constrain(panel3,t_wave,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,20,0,0);
	constrain(panel3,cb_wave[0],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel3,cb_wave[1],3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	
	constrain(panel4,power,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel4,t_power,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel4,cb_power[0],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel4,cb_power[1],3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel5,spectral,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel5,t_spectral,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,8);
	constrain(panel5,cb_spectral[0],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,4,0,0,5);
	constrain(panel5,cb_spectral[1],3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	
	constrain(panel6,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,40);
	constrain(panel6,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,40,0,40);
	constrain(panel6,def,2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,30,0,0);
	constrain(panel7,pulse,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,35,0,0);
	constrain(panel7,t_pulse,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,5,0,137);
	
	constrain(this,panel1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,10,0,5,0);
	constrain(this,panel2,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,5,0,15,0);
	constrain(this,panel3,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,15,0,10,0);
	constrain(this,panel4,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,6,0,6,0);
	constrain(this,panel5,0,4,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,6,0,6,0);
	constrain(this,panel7,0,5,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,6,0,15,0);
	constrain(this,panel6,0,6,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,15,0,0,0);
	
	this.pack();
	this.show();
      }
    public boolean action(Event e,Object arg)
      {
	if (e.target == ok)
	  {
	    // get_data();
	    update_data();
	    dispose();
	    return true;
	  }
	else if (e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else if((e.target == c_names)||(e.target==def))
	  {
	    try{getinfo();}
	    catch(IOException c){c.getMessage();}
	    return true;
	  }
	else return false;
      } 
    
    public void getinfo() throws IOException
      {
	/*
	String filename = new String(c_names.getSelectedItem());
	filename = filename.replace(':','_');
	filename = filename.replace(' ','_');
	filename = filename.concat(".txt");
	
	URL url = new URL("http://www331.jpl.nasa.gov/group1/focas_birju/laser/"+filename);
	URLConnection connection = url.openConnection();
	connection.connect();
	
	DataInputStream in = new DataInputStream(connection.getInputStream());
	
	t_wave.setText(String.valueOf((((Double.valueOf(in.readLine())).doubleValue())*(1E9))));
	t_power.setText(in.readLine());
	b_power.setCurrent(cb_power[1]);
	b_wave.setCurrent(cb_wave[0]);
	b_power.setCurrent(cb_power[1]);
	b_spectral.setCurrent(cb_spectral[1]);
	in.readLine(); //peak power
	t_spectral.setText(in.readLine());
	b_spectral.setCurrent(cb_spectral[1]);
	in.readLine(); // pulse to pulse..
	in.readLine(); //in space
	t_pulse.setText(in.readLine());
	String temp = new String(in.readLine());
	
	if (temp.equals("CW"))
	  {
	    b_laser.setCurrent(cb_laser[0]);
	  }
	else
	  {
	    
	    b_laser.setCurrent(cb_laser[1]);
	  }
	*/
	try
	  {String ex = "SELECT * " + "FROM laser " + "WHERE name = '" +c_names.getSelectedItem() + "' ";
	    Statement stmt = C.createStatement();
	    
	   
	    ResultSet results = stmt.executeQuery(ex);
	    t_wave.setText( results.getString(2));
	    t_power.setText( results.getString(3));
	    t_spectral.setText(results.getString(5));
	    t_pulse.setText(results.getString(8));
	  }
	catch(SQLException E){}
	
      }
    public void update_data()
      {
	double temp=0;
	LaserName = c_names.getSelectedItem();
	LaserType = cb_laser[0].getState();
	Wavelength_units = cb_wave[0].getState();
	Power_units = cb_power[0].getState();
	Spectral_units = cb_spectral[0].getState();
	
	temp =(Double.valueOf(t_wave.getText())).doubleValue(); 
	if(Wavelength_units) LaserWavelength = temp/1E9;
	else LaserWavelength = temp/1E6;
	temp = (Double.valueOf(t_power.getText())).doubleValue();
	if(Power_units) LaserAvgPower = temp/1000;
	else LaserAvgPower = temp;
	
	LaserSpectralWidth = (Double.valueOf(t_spectral.getText())).doubleValue();
	LaserPulseWidth =  (Double.valueOf(t_pulse.getText())).doubleValue();
	t_laser.setText(LaserName);
	t_laser.setAlignment(t_laser.CENTER);
      }
  }
  
  public class location_r_frame extends Frame
  {
    private Button ok,cancel;
    private Label label1,label2,label3;
    private TextField t_altitude,t_latitude;
    private CheckboxGroup b_units;
    private Checkbox[] cb_units;
    private Choice c_locations;
    public location_r_frame(String Title)
      {
	super(Title);
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	label1 = new Label("Altitude: ");
	label2 = new Label("Latitude: ");
	label3 = new Label("Location: ");
	t_altitude = new TextField(String.valueOf(Altitude),10);
	t_latitude = new TextField(String.valueOf(Latitude),10);
	b_units = new CheckboxGroup();
	cb_units = new Checkbox[3];
	cb_units[0] = new Checkbox("m",b_units,(alt_units == "m"));
	cb_units[1] = new Checkbox("ft",b_units,(alt_units == "ft"));
	cb_units[2] = new Checkbox("km",b_units,(alt_units == "km"));
	c_locations = new Choice();
	c_locations.addItem("Moon");
	c_locations.addItem("Shuttle");
	c_locations.addItem("Space Station");
	c_locations.addItem("LEO");
	c_locations.addItem("GEO");
	c_locations.addItem("Venus");
	c_locations.addItem("Mars");
	c_locations.addItem("Jupiter");
	c_locations.addItem("Saturn");
	c_locations.addItem("Uranus");
	c_locations.addItem("Neptune");
	c_locations.addItem("Pluto");
	c_locations.addItem("Comet");
	c_locations.addItem("Asteroid");
	c_locations.addItem("Other");
	c_locations.addItem("TMF");
	c_locations.addItem("Starfire");
	c_locations.addItem("Strawberry Peek");
	c_locations.addItem("Mt. Lemmon");
	c_locations.addItem("Goldstone");
	c_locations.addItem("Mesa");
	c_locations.addItem("JPL");
	c_locations.select(Location);
	r_index = c_locations.getSelectedIndex();
	Panel panel1,panel2,panel3,panel4;
	panel1 = new Panel();
	panel2 = new Panel();
	panel3 = new Panel();
	panel4 = new Panel();
	
	
	GridBagLayout gridbag = new GridBagLayout();
	this.setLayout(gridbag);
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	
	constrain(panel1,label3,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel1,c_locations,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,label1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,t_altitude,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_units[0],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_units[1],3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,cb_units[2],4,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel3,label2,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel3,t_latitude,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(panel4,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,10);
	constrain(panel4,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,0);
	
	constrain(this,panel1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel2,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel3,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,0);
	constrain(this,panel4,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	this.pack();
	this.show();
	
	
      }
    
    
    public boolean action(Event e,Object arg)
      {
	if(e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	Altitude = (Double.valueOf(t_altitude.getText())).doubleValue();
	Latitude = (Double.valueOf(t_latitude.getText())).doubleValue();
	alt_units = (b_units.getCurrent()).getLabel();
	Location = c_locations.getSelectedItem();
	r_index = c_locations.getSelectedIndex();
	t_location_r.setText(Location);
	t_location_r.setAlignment(t_location_t.CENTER);
      }
	
    
    
  }
  
  public class data_format_frame extends Frame
  {
    private Button ok,cancel;
    private Choice PP,N1;
    private CheckboxGroup b_data,b_modulation,b_coding;
    private Checkbox[] cb_data,cb_modulation,cb_coding;
    private Panel panel1,panel2,panel3,panel4,panel5,panel6;
    private TextField t_data,t_ber,t_laser,t_pulse,t_k;
    
    public data_format_frame(String title)
      {
	super(title);
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	
	t_data = new TextField(String.valueOf(DataRate),10);
	t_ber = new TextField(String.valueOf(BER),10);
	t_laser = new TextField(String.valueOf(LaserMod),10);
	t_pulse = new TextField(String.valueOf(PulseSlot),10);
	t_k = new TextField(String.valueOf(K),10);
	b_data = new CheckboxGroup();
	cb_data = new Checkbox[3];
	cb_data[0] = new Checkbox("Kbps",b_data,(DataRate_units=="Kbps"));
	cb_data[1] = new Checkbox("Mbps",b_data,(DataRate_units=="Mbps"));
	cb_data[2] = new Checkbox("Gbps",b_data,(DataRate_units=="Gbps"));
	
	b_modulation  = new CheckboxGroup();
	cb_modulation = new Checkbox[2];
	cb_modulation[0] = new Checkbox("Pulse-position modulation",b_modulation,Modtype);
	cb_modulation[1] = new Checkbox("On-Off keying (Direct Detection)",b_modulation,!Modtype);
	
	b_coding = new CheckboxGroup();
	cb_coding = new Checkbox[3];
	cb_coding[0] = new Checkbox("None",b_coding,Coding_type.equals("NONE"));
	cb_coding[1] = new Checkbox("Reed-Solomon code",b_coding,Coding_type.equals("RS"));
	cb_coding[2] = new Checkbox("Binary",b_coding,Coding_type.equals("Binary"));
	PP = new Choice();
	PP.addItem("2");
	PP.addItem("4");
	PP.addItem("8");
	PP.addItem("16");
	PP.addItem("32");
	PP.addItem("64");
	PP.addItem("128");
	PP.addItem("256");
	PP.addItem("512");
	PP.addItem("1024");
	PP.select(Pindex);
	
	N1 = new Choice();
	
	N1.addItem("3");
	N1.addItem("7");
	N1.addItem("15");
	N1.addItem("31");
	N1.addItem("63");
	N1.addItem("127");
	N1.addItem("255");
	N1.addItem("511");
	N1.addItem("1023");
	N1.select(Nindex);
	GridBagLayout gridbag = new GridBagLayout();
	panel1 = new Panel();
	panel2 = new Panel();
	panel3 = new Panel();
	panel4 = new Panel();
	panel5 = new Panel();
	panel6 = new Panel();
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	panel3.setLayout(gridbag);
	panel4.setLayout(gridbag);
	panel5.setLayout(gridbag);
	panel6.setLayout(gridbag);
	this.setLayout(gridbag);
	constrain(panel1,new Label("Data Rate:"),0,0,1,1);
	constrain(panel1,t_data,1,0,1,1);
	constrain(panel1,cb_data[0],2,0,1,1);
	constrain(panel1,cb_data[1],3,0,1,1);
	constrain(panel1,cb_data[2],4,0,1,1);
	constrain(panel1,new Label("Required BER:"),0,1,1,1);
	constrain(panel1,t_ber,1,1,1,1);
	Label label1 = new Label("Modulation");
	label1.setFont(new Font("Helvetica",Font.BOLD,14));
	constrain(panel2,label1,0,0,1,1);
	constrain(panel2,cb_modulation[0],0,1,1,1);
	constrain(panel2,PP,1,1,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,0,0,10);
	constrain(panel2,cb_modulation[1],0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,10,0);
	constrain(panel2,new Label(" Laser-modulation extinction ratio:"),0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,5,0,0,0);
	constrain(panel2,t_laser,1,3,1,1);
	constrain(panel2,new Label("Pulsewidth to slot:"),0,4,1,1,GridBagConstraints.NONE,GridBagConstraints.EAST,0.0,0.0,0,0,0,0);
	constrain(panel2,t_pulse,1,4,1,1);
	
	Label label2 = new Label("Coding");
	label2.setFont(new Font("Helvetica",Font.BOLD,14));
	
	constrain(panel3,label2,0,0,1,1);
	constrain(panel3,cb_coding[0],0,1,1,1);
	constrain(panel3,cb_coding[1],0,2,1,1);
	constrain(panel3,cb_coding[2],0,3,1,1);
	constrain(panel3,new Label("N"),1,2,1,1,0,10,0,0);
	constrain(panel3,N1,2,2,1,1);
	constrain(panel3,new Label("K"),1,3,1,1,0,10,0,0);
	constrain(panel3,t_k,2,3,1,1);
	constrain(panel5,panel3,0,0,1,1);
	
	constrain(panel6,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,10);
	constrain(panel6,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,10,0,0);
	constrain(this,panel1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,10,0,0,0);
	constrain(this,panel2,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,10,0,0,0);
	constrain(this,panel5,0,2,1,1,GridBagConstraints.NONE,GridBagConstraints.WEST,0.0,0.0,0,26,0,0);
	constrain(this,panel6,0,3,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,20,0,0,0);
	this.pack();
	this.show();
      }
    public boolean action(Event e,Object arg)
      {
	
	if(e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if(e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	
	LaserMod = (Double.valueOf(t_laser.getText())).doubleValue();
	PulseSlot = (Double.valueOf(t_pulse.getText())).doubleValue();
	DataRate = (Double.valueOf(t_data.getText())).doubleValue();
	BER = (Double.valueOf(t_ber.getText())).doubleValue();
	K = (Double.valueOf(t_k.getText())).doubleValue();
	N =  (Double.valueOf(N1.getSelectedItem())).doubleValue();
	P = (Double.valueOf(PP.getSelectedItem())).doubleValue();
	Nindex = N1.getSelectedIndex();
	Pindex = PP.getSelectedIndex();
	Modtype = cb_modulation[0].getState();
	Coding_type=(b_coding.getCurrent()).getLabel();
	DataRate_units =  (b_data.getCurrent()).getLabel();
      }
    
  }
  
  public class relay_frame extends Frame
  {
    private Button ok,cancel;
    private Label l;
    private TextField t_relay_ops;
    private CheckboxGroup b_optics;
    private Checkbox[] cb_optics;
    private Panel panel1,panel2;
    
    
    public relay_frame(String title)
      { 
	
	
	super(title);
	ok = new Button("Ok");
	cancel = new Button("Cancel");
	l = new Label("Optical Loss");
	t_relay_ops = new TextField(String.valueOf(RelayOpticsTrans),10);
	b_optics = new CheckboxGroup();
	cb_optics = new Checkbox[2];
	cb_optics[0] = new Checkbox("%",b_optics,Relay_units);
	cb_optics[1] = new Checkbox("dB",b_optics,!Relay_units);
	GridBagLayout gridbag = new GridBagLayout();
	panel1 = new Panel();
	panel2 = new Panel();
	panel1.setLayout(gridbag);
	panel2.setLayout(gridbag);
	this.setLayout(gridbag);
	
	constrain(panel1,l,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel1,t_relay_ops,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel1,cb_optics[0],2,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel1,cb_optics[1],3,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(panel2,ok,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,40);
	constrain(panel2,cancel,1,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,40,0,0);
	
	constrain(this,panel1,0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	constrain(this,panel2,0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.0,0.0,0,0,0,0);
	
	this.pack();
	this.show();
      }
    public boolean action(Event e,Object arg)
      {
	if (e.target == ok)
	  {
	    update();
	    dispose();
	    return true;
	  }
	else if (e.target == cancel)
	  {
	    dispose();
	    return true;
	  }
	else return false;
      }
    public void update()
      {
	RelayOpticsTrans =  (Double.valueOf(t_relay_ops.getText())).doubleValue();
	Relay_units = cb_optics[0].getState();
      }
  }
  public void getinfo() throws IOException
    {
      String filename = new String(links.getSelectedItem());
      filename = filename.replace('(','_');
      filename = filename.replace(' ','_');
      filename = filename.replace(')','_');
      filename = filename.replace('-','_');
     System.out.println(filename);
      
      URL url = new URL("http://www331.jpl.nasa.gov/group1/focas_birju/saved_links/"+filename);
      URLConnection connection = url.openConnection();
      connection.connect();
      
      DataInputStream in = new DataInputStream(connection.getInputStream());
      String temp;
      Location_t = in.readLine();
      Location = in.readLine();
      newTRANSLoc = in.readLine();
      newRECloc = in.readLine();
      Range = (Double.valueOf(in.readLine())).doubleValue();
      DataRate = (Double.valueOf(in.readLine())).doubleValue();
      BER = (Double.valueOf(in.readLine())).doubleValue();
      temp= in.readLine();
      if(temp.equals("PPM")) Modtype=true;
      else Modtype=false;
      P = (Double.valueOf(in.readLine())).doubleValue();
      Coding_type = in.readLine();
      LaserName = in.readLine();
      temp = in.readLine();
      if(temp.equals("CW"))LaserType=true;
      else LaserType=false;
      LaserWavelength =  (Double.valueOf(in.readLine())).doubleValue();
      LaserAvgPower =  (Double.valueOf(in.readLine())).doubleValue();
      LaserPulseWidth =  (Double.valueOf(in.readLine())).doubleValue();
      LaserMod =  (Double.valueOf(in.readLine())).doubleValue();
      laser_variation =  (Double.valueOf(in.readLine())).doubleValue();
      LaserSpectralWidth =  (Double.valueOf(in.readLine())).doubleValue();
      temp = in.readLine();
      if(temp.equals("Yes"))LaserInSpace=true;
      else LaserInSpace=false;
      LS_TxLossMO =  (Double.valueOf(in.readLine())).doubleValue();
      T_TelescopeName = in.readLine();
      temp = in.readLine();
      if(temp.equals("Airy")){
	BeamProfile= true;
	System.out.println(temp);
      }
      else
	{
	  BeamProfile=false;
	  System.out.println("op");
	}
  
      ApertureDiameter =  (Double.valueOf(in.readLine())).doubleValue();
      SecondaryObsuration =ApertureDiameter* (Double.valueOf(in.readLine())).doubleValue();
      BeamWidth =  (Double.valueOf(in.readLine())).doubleValue();
      Surface_Quality = (Double.valueOf(in.readLine())).doubleValue();
      TxLossTO = (Double.valueOf(in.readLine())).doubleValue();
      TxLossSS = (Double.valueOf(in.readLine())).doubleValue();
      temp = in.readLine();
      if(temp.equals("Yes"))inSpace=true;
      else inSpace=false;
      PointingJitter = (Double.valueOf(in.readLine())).doubleValue();
      PointingOffset = (Double.valueOf(in.readLine())).doubleValue();
      pt_allowance = (Double.valueOf(in.readLine())).doubleValue();
      in.readLine();
      (Double.valueOf(in.readLine())).doubleValue();
      (Double.valueOf(in.readLine())).doubleValue();
      Trans =  (Double.valueOf(in.readLine())).doubleValue();
      Angle =  (Double.valueOf(in.readLine())).doubleValue();
      atm_adj =  (Double.valueOf(in.readLine())).doubleValue();
      Seeing = (Double.valueOf(in.readLine())).doubleValue();
      atmosMODEL = in.readLine();
      Conditions = in.readLine();
      Stars = in.readLine();
      Planets = in.readLine();
      RxSrcDist = (Double.valueOf(in.readLine())).doubleValue();
      R_TelescopeName = in.readLine();
      R_ApertureDiameter = (Double.valueOf(in.readLine())).doubleValue();
      R_SecondaryObsuration = (Double.valueOf(in.readLine())).doubleValue()*R_ApertureDiameter;
      RxLossTO = (Double.valueOf(in.readLine())).doubleValue();
      temp = in.readLine();
      if(temp.equals("Yes")) R_inSpace = true;
      else R_inSpace = false;
      Split = (Double.valueOf(in.readLine())).doubleValue();
      Redundancy = (Double.valueOf(in.readLine())).doubleValue();
      Optical = (Double.valueOf(in.readLine())).doubleValue();
      Pointing = (Double.valueOf(in.readLine())).doubleValue();
      Peak = (Double.valueOf(in.readLine())).doubleValue();
      Spectral = (Double.valueOf(in.readLine())).doubleValue();
      Truncation  = (Double.valueOf(in.readLine())).doubleValue();
      Field = (Double.valueOf(in.readLine())).doubleValue();
      Detector = in.readLine();
      detectorTYPE = in.readLine();
      Quantum = (Double.valueOf(in.readLine())).doubleValue();
      Ionization = (Double.valueOf(in.readLine())).doubleValue();
      Gain = (Double.valueOf(in.readLine())).doubleValue();
      BulkDark = (Double.valueOf(in.readLine())).doubleValue();
      SurfaceDark = (Double.valueOf(in.readLine())).doubleValue();
      RiseFall = (Double.valueOf(in.readLine())).doubleValue();
      Capacitance = (Double.valueOf(in.readLine())).doubleValue();
      DetectorDiameter = (Double.valueOf(in.readLine())).doubleValue();
      AmpModel = in.readLine();
      AmpNEI = (Double.valueOf(in.readLine())).doubleValue();
      ampBANDWIDTH = (Double.valueOf(in.readLine())).doubleValue();
      ampRANGE = (Double.valueOf(in.readLine())).doubleValue();
      ampGAIN = (Double.valueOf(in.readLine())).doubleValue();
      PulseSlot = (Double.valueOf(in.readLine())).doubleValue();
      in.readLine();
      (Double.valueOf(in.readLine())).doubleValue();
      (Double.valueOf(in.readLine())).doubleValue();
      N = (Double.valueOf(in.readLine())).doubleValue();
      K = (Double.valueOf(in.readLine())).doubleValue();
      coding_adj = (Double.valueOf(in.readLine())).doubleValue();
      
	
    }
  public void constrain(Container container, Component component,int grid_x,int grid_y,int grid_width, int grid_height, int fill, int anchor, double weight_x, double weight_y,int top,int left,int bottom,int right)
    {
      GridBagConstraints c = new GridBagConstraints();
      c.gridx = grid_x;c.gridy=grid_y;
      c.gridwidth = grid_width;c.gridheight = grid_height;
      c.fill = fill;c.anchor=anchor;
      c.weightx = weight_x;c.weighty=weight_y;
      if(top+bottom+left+left >0)
	{
	  c.insets = new Insets(top,left,bottom,right);
	}
      ((GridBagLayout)container.getLayout()).setConstraints(component,c);
      container.add(component);
    }
  
  public void constrain(Container container, Component component,int grid_x,int grid_y,int grid_width, int grid_height)
    {
      constrain(container,component,grid_x,grid_y,grid_width,grid_height,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.0,0.0,0,0,0,0);
    }
  
  public void constrain(Container container, Component component,int grid_x,int grid_y,int grid_width, int grid_height,int top,int left,int bottom, int right)
    {
      constrain(container,component,grid_x,grid_y,grid_width,grid_height,GridBagConstraints.NONE, GridBagConstraints.CENTER,0.0,0.0,top,left,bottom,right);
    }
}