import java.awt.*;
import java.applet.Applet;

public class Converter extends Applet {

int fromindex = 0; //from unit index
int toindex = 0;   // to unit index

/* A place to print the conversion factor */
TextField textfield = new TextField(12);

/* where the choices are displayed */
Panel listpanel = new Panel();

/* where the test field is displayed */
Panel textpanel = new Panel();

Choice unit1 = new Choice();
Choice unit2 = new Choice();

/* array of conversion factors */

String values[][] = {
 {"1.000", "1.000 E-2", "1.000 E-5", "3.397 E-1", "3.937 E-2", "6.214 E-6"},
 {"1.000 E+2", "1.000", "1.000 E-3", "39.37", "3.28", "6.214 E-4"},
 {"1.00 E+5", "1.000 E+3", "1.000", "3.937 E+4", "3.281 E+3", "6.214 E+1"},
 {"2.52", "0.0254", "2.54 E-5", "1.000", "0.0833", "1.578 E-5"},
 {"30.48", "0.3048", "3.048 E-4", "12.0", "1.000", "1.894 E-4"},
 {"1.609 E+5", "1.609 E+3", "1609", "6.336 E+4", "5280", "1.000"}

};

/* user interface called at start */

public void init() {

textfield.setText(values[fromindex][toindex]);
textfield.setEditable (false);

this.setLayout(new BorderLayout());
listpanel.setLayout(new FlowLayout());
/* add some colors */
listpanel.setBackground(Color.white);
listpanel.setForeground(Color.blue);
textpanel.setBackground(Color.white);
textpanel.setForeground(Color.blue);

add("North", listpanel); 
add("South", textpanel); 

Label fromlabel = new Label ("To Convert From  ", 1);
/* add some colors WORKS*/
fromlabel.setBackground(Color.yellow);
fromlabel.setForeground(Color.black);

listpanel.add(fromlabel);
  unit1.addItem("Centimeters");
  unit1.addItem("Meters");
  unit1.addItem("Kilometers");
  unit1.addItem("Inches");
  unit1.addItem("Feet");
  unit1.addItem("Miles");
   listpanel.add(unit1);


Label tolabel = new Label ("  to       ", 1);
/* add some colors WORKS*/
tolabel.setBackground(Color.yellow);
tolabel.setForeground(Color.black);

listpanel.add(tolabel);
  unit2.addItem("Centimeters");
  unit2.addItem("Meters");
  unit2.addItem("Kilometers");
  unit2.addItem("Inches");
  unit2.addItem("Feet");
  unit2.addItem("Miles");
   listpanel.add(unit2);

Label multlabel = new Label ("Multiply by   ", 1);
/* add some colors  WORKED*/
multlabel.setBackground(Color.yellow);
multlabel.setForeground(Color.black);

textpanel.add(multlabel);
textpanel.add(textfield);

}

/* called when action occurs  */

public boolean action(Event evt, Object arg) {

if (evt.target.equals (unit1)) {
     fromindex = unit1.getSelectedIndex();
     textfield.setText(values[fromindex][toindex]);
     repaint();
  } else if (evt.target.equals (unit2)){
     toindex = unit2.getSelectedIndex();
     textfield.setText(values[fromindex][toindex]);
     repaint();
  }
  return true;
}

/*  application entry point */

public static void main (String args[]) {

    Frame f = new Frame("Converter ");

    Converter converter = new Converter();
/* add some colors  NOT WORKING*/
    f.setBackground(Color.red);
    f.setForeground(Color.white);

    converter.init();
    converter.start();
    f.add("Center", converter);
    f.show();
}
}

   
   


