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

public class Energytool extends Applet { 

int fromindex = 0; 
int toindex = 0; 

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

/* 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", "2.51996 E2", "1.0544 E10", "6.5805 E21", "2.5020 E4", "777.649",
"1.0751 E7","3.93 E-4","1054.35","0.2520","107.514","2.92875 E-4",
"10.4056","1 E-5"},

{"3.971 E-3", "1.000", "4.184 E7", "2.611 E19", "99.2878", "3.08596",
"42664.9","1.558 E-6","4.184","1 E-3","0.42665","1.162 E-6",
"0.04129","3.971 E-8"},

{"9.4845 E-11", "2.3885 E-8", "1.000", "6.241 E11", "2.373 E-6", "7.376 E-8",
"1.0197 E-3","3.725 E-14","1 E-7","2.3901 E-11","1.0197 E-8","2.778 E-14",
"9.869 E-10","9.4847 E-16"},

{"1.520 E-22", "3.8266 E-20", "1.6021 E-12", "1.000", "3.802 E-18", 
"1.182 E-19","1.634 E-15","5.968 E-26","1.6021 E-19","3.829 E-23",
"1.6337 E-20","4.4506 E-26","1.5811 E-21","1.520 E-27"},

{"3.9967 E-5","1.007 E-2", "4.214 E5", "2.630 E17", "1.000", "3.108 E-2",
"4.297 E2","1.5697 E-8","4.2139 E-2","1.007 E-5","4.297 E-3","1.1706 E-8",
"4.1595 E-4","3.9994 E-10"},

{"1.2859 E-3", "0.3238", "1.3558 E7", "8.46062 E18", "32.17405", "1.000",
"13825.5","5.0505 E-7","1.3558","3.24 E-4","0.13825","3.76616 E-7",
"1.33809 E-2","1.28675 E-8"},

{"9.3 E-8", "2.344 E-5", "980.665", "6.1196 E14", "2.33 E-3", "7.233 E-5",
"1.000","3.653 E-11","9.806 E-5","2.343 E-8","1 E-5","2.724 E-11",
"9.6784 E-7","9.3071 E-13"},

{"2546.1", "641616.0", "2.685 E13", "1.67521 E25", "6.37046 E7", "1.98 E6",
"2.73745 E10","1.000","2.685 E6","641.2","273745.0","0.7457","2.6494 E4",
"2.5478 E-2"},

{"9.485 E-4", "0.23901", "1 E7", "1.6021 E-19", "23.73", "0.7376","10197.2",
"3.7251 E-7","1.000","2.3901 E-4","0.10197","2.78 E-7"," 9.869 E-3",
"9.4904 E-9"},

{"3.971", "1000.0", "4.184 E10", "2.611 E22", "99.2878 E3", "3.08596 E3",
"4.2665 E7","1.558 E-3","4.184 E3","1.000","4.2665 E2","1.162 E-3","41.29",
"3.971 E-5"},

{"9.3011 E-3", "2.34384", "9.807 E7", "6.1196 E19", "232.715", "7.233",
"1 E5","3.653 E-6","9.80665","2.34384 E-3","1.000","2.724 E-6","9.6784 E-2",
"9.3071 E-8"},

{"3.4146 E3", "859845.0", "3.6 E13", "5.7679 E-13", "8.5428 E7", "2.655 E6",
"3.6710 E10","1.341","3.6 E6","859.845","367098.0","1.000","3.5528 E4",
"3.4165 E-2"},

{"9.611 E-2", "24.2183", "1.01327 E9", "1.6235 E-17", "2.4045 E3", "7.4739 E1",
"1.0332 E6","3.7745 E-5","101.3274","2.4218 E-2","10.332","2.8169 E-5","1.000",
"9.6164 E-7"},

{"1 E5", "2.51996 E5", "1.0544 E15", "6.5805 E26", "2.50201 E9", "7.77649 E7",
"1.0751 E12","39.3","1.05435 E8","2.520 E4","1.07514 E7","2.92875 E1",
"1.04056 E6","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.black);
textpanel.setBackground(Color.white);
textpanel.setForeground(Color.black);

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

Label fromlabel = new Label ("To Convert From  ", 1);

/* add some colors WORKS*/
fromlabel.setBackground(Color.orange);
fromlabel.setForeground(Color.black);

listpanel.add(fromlabel);
  unit1.addItem("Btu");
  unit1.addItem("Cal-grams");
  unit1.addItem("Ergs");
  unit1.addItem("eV");
  unit1.addItem("Foot-poundals");
  unit1.addItem("Foot pound-force");
  unit1.addItem("Gram-force cm");
  unit1.addItem("Hp-hours");
  unit1.addItem("Joules");
  unit1.addItem("Kg-calories");
  unit1.addItem("Kg-force meters");
  unit1.addItem("KW-hours");
  unit1.addItem("Liter-atm");
  unit1.addItem("Therms");
   listpanel.add(unit1);


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

listpanel.add(tolabel);
  unit2.addItem("Btu");
  unit2.addItem("Cal-grams");
  unit2.addItem("Ergs");
  unit2.addItem("eV");
  unit2.addItem("Foot-poundals");
  unit2.addItem("Foot pound-force");
  unit2.addItem("Gram-force cm");
  unit2.addItem("Hp-hours");
  unit2.addItem("Joules");
  unit2.addItem("Kg-calories");
  unit2.addItem("Kg-force meters");
  unit2.addItem("KW-hours");
  unit2.addItem("Liter-atm");
  unit2.addItem("Therms");
   listpanel.add(unit2);

Label multlabel = new Label ("Multiply by   ", 1);
/* add some colors  WORKED*/
multlabel.setBackground(Color.orange);
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("Energytool");

    Energytool energy = new Energytool();

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

}

   
   


