import java.awt.*;
import java.applet.*;
import java.awt.event.*; 
public class Calculate extends Applet implements ActionListener {
	
	Button btnClick; 
	TextField txt;
	private float total = 0; //variable to hold sum of numbers
	
	public void init() {		
		btnClick = new Button("Add to Total"); 
		btnClick.setBounds(40,120,300,40); 
  		add(btnClick);  
  		txt = new TextField("Type a number to add",  40);
  		txt.setBounds(40,0,200,30);
  		add(txt);	
  		btnClick.addActionListener(this); 
	}	
	public void paint(Graphics g) {	
		g.drawString("The Total is: " + total, 50, 60 );		
	}
	public void actionPerformed(ActionEvent event){   
  		if (event.getSource() == btnClick)  {
  			total = total + Float.parseFloat(txt.getText());
  	        //Float.parseFloat converts a string to a number
  			repaint(); 		
		}
	}
}





