import java.awt.*; import java.awt.event.*; public class inches2 extends Frame implements ActionListener{ Label label1, label2, label3; TextField inch, cent; Button cinch, ccent; public inches2() { // inches1 constructor // Frame Layout design this.setVisible(true); this.setLayout(null); this.setSize(300,200); this.setTitle("Inches and Centimeter Conversion"); // end Frame Layout design // Labels Layout label1 = new Label(); label1.setBounds(10,50,75,21); label1.setText("Inches"); add(label1); label2 = new Label(); label2.setBounds(10,100,75,21); label2.setText("Centimeters"); add(label2); // end of Label Layout // TextField Layout inch = new TextField(); inch.setBounds(100,50,100,25); add(inch); cent = new TextField(); cent.setBounds(100,100,100,25); add(cent); // end of TextField Layout // Button Layout cinch = new Button("Convert to Inches"); cinch.setBounds(10,150,120,30); add(cinch); ccent = new Button("Convert to Centimeter"); ccent.setBounds(150,150,130,30); add(ccent); // end of Button Layout validate(); // refresh frame // Assignment of ActionListener cinch.addActionListener(this); ccent.addActionListener(this); // end of Assignment } public void actionPerformed(ActionEvent e) { /* This method is executed whenever an action is performed on the objects assigned with ActionListener */ // if cinch Button is pressed if(e.getSource()==cinch) { double i ; String iString; iString = cent.getText(); i=Double.parseDouble(iString); i = i / 2.54; iString=String.valueOf(i); inch.setText(iString); } // if ccent Button is pressed if(e.getSource()==ccent) { double c; String cString; cString = inch.getText(); c = Double.parseDouble(cString); c = c * 2.54; cString = String.valueOf(c); cent.setText(cString); } } public static void main(String arg[]) { new inches2(); } }