// Applet to convert metres to inches

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

// Use Action listener for receiving action events
// when the action event happens, the objects actionPerformed method is invoked

public class ConvertM extends Applet implements ActionListener
{
	private TextField one;
	private TextArea two;
	private Label label;
	private Font font;
	private Button calculate;
	private Button clear;
	
	//method called by the browser or applet viewer
	//when an appletr is going to be executed
	
	public void init()
	{
		one = new TextField(10);
		two = new TextArea(5,20);
		
		font = new Font("TimesRoman",Font.ITALIC,14);
		label = new Label();
		
		// set label text
		label.setText("Enter Metres here");
		//set label font
		label.setFont(font);
		
		// set buttons
		
		calculate = new Button("Calculate");
		// add action listener to receive action events fromthe comment text field 
		calculate.addActionListener(this);
		
		clear = new Button("Clear");
		clear.addActionListener(this);
		
		//add text areas and buttons to the applet
		
		add(label);
		add(one);
		add(two);
		add(calculate);
		add(clear);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		// checks if the button if pressed
		
		if(e.getSource()==calculate)
		{
			double inches;
			String s = one.getText(); // reads in the text
			if(!s.equals(""))
			{
				// creates double metre and converts it from text to a number
				double metre = Double.parseDouble(s);
				inches = (metre*39.37);
				s=Double.toString(inches);
				two.setText(s);
			}
			else two.setText("No number entered");
		}
		if(e.getSource()==clear)
		{
			one.setText("");
			two.setText("");
		}
	}
}// ends class					
				
				