/* CSCI 15A- 5 Assignment 2
 * 
 * Convert from Assignment 1 as an applet
 * Calculate Simple Interest and the total Amount
 *
 * Author: Alex Chan September 23, 1998
 */

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Interest2 extends Applet implements ActionListener {

	TextField tPrinciple, tRate, tTime;
	Label lPrinciple, lRate, lTime, lSimple;
	Button CalculateButton;

	double Principle, Rate, Time, Simple_Interest, Amount;
	 
	public void init() {
		
		//Create the TextField, the Label, the Button
		  tPrinciple = new TextField(10);
		  tRate = new TextField(10);
		  tTime = new TextField(10);
		  lPrinciple = new Label("Prinicple = ");
		  lRate = new Label("Rate of Interest = ");
		  lTime = new Label("Time (in years)= ");
		  CalculateButton = new Button("Calculate");
		  		
		//Lay out the Components
		  add(new Label("Calculate Simple Interest and Total Amount:"));
		  add(lPrinciple);
		  add(tPrinciple);
		  add(lRate);
		  add(tRate);
		  add(lTime);
		  add(tTime);
		  add(CalculateButton);
		  
		//Register the Component Listener
		  CalculateButton.addActionListener(this);	
				  
	}
	
	//Respnd to Action Event
	public void actionPerformed (ActionEvent e) {
 		
		//GetText and Calculate		  	  
		  Principle = new Double(tPrinciple.getText()).doubleValue();
		  Rate = new Double(tRate.getText()).doubleValue();
		  Time = new Double(tTime.getText()).doubleValue();
		  
		  Simple_Interest = (Principle * Rate * Time) / 100;
		  Amount = Principle + Simple_Interest;
    	          repaint();
	}

	public void paint (Graphics g) {	
	
	    //Output
		  g.drawString("Simple Interest = " + Simple_Interest, 0, 80);
		  g.drawString("Amount = " + Amount, 0, 95);		
	}

}

