skugpezz 0 Newbie Poster

I am trying to code a calculator and I am stuck. How do I set the resultField.setText to values ?

import java.awt.*; //Contains all of the classes for creating user interfaces and for painting graphics and images
import java.applet.*;
import java.awt.event.*; //Provides interfaces and classes for dealing with different types of events fired by AWT components.

public class progcalc extends Applet implements ActionListener
{
String myBuffer;
String firstBuffer;
String secondBuffer;

String operation;

int result;
String passtoresult;

Panel row1 = new Panel();
Panel row2 = new Panel();
Panel row3 = new Panel();

Label titleLabel = new Label("Calculator", Label.CENTER);
//A Label object is a component for placing text in a container.
//A label displays a single line of read-only text.
//http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Label.html
TextField resultField = new TextField(15);
//A TextField object is a text component 
//that allows for the editing of a single line of text. 
//http://java.sun.com/j2se/1.4.2/docs/api/java/awt/TextField.html

Button one = new Button ("1");
Button zero = new Button ("0");
Button two = new Button ("2");
Button three = new Button ("3");
Button four = new Button ("4");
Button five = new Button ("5");
Button six = new Button ("6");
Button seven = new Button ("7");
Button eight = new Button ("8");
Button nine = new Button ("9");
Button add = new Button ("add");
Button subtract = new Button ("subtract");
Button multiply = new Button ("multiply");
Button divide = new Button ("divide");
Button equals = new Button ("equals");

public void init()
{
myBuffer="";
firstBuffer="";
secondBuffer="";

one.addActionListener(this);
// addDctionListener This class creates a labeled button.
// http://java.sun.com/j2se/1.3/docs/ap...wt/Button.html
zero.addActionListener(this);
two.addActionListener(this);
three.addActionListener(this);
four.addActionListener(this);
five.addActionListener(this);
six.addActionListener(this);
seven.addActionListener(this);
eight.addActionListener(this);
nine.addActionListener(this);
add.addActionListener(this);
subtract.addActionListener(this);
multiply.addActionListener(this);
divide.addActionListener(this);
equals.addActionListener(this);

setBackground(Color.white);

GridLayout line1 = new GridLayout(2,1,100,10);
//The GridLayout class is a layout manager that 
//lays out a container's components in a rectangular grid.

row1.setLayout(line1);
row1.add(titleLabel);row1.add(resultField);
add(row1);

GridLayout line2 = new GridLayout(3,4,2,2);
row2.setLayout(line2);
row2.add(one);row2.add(two);
row2.add(three);row2.add(four);row2.add(five);
row2.add(six);row2.add(seven);row2.add(eight);row2 .add(nine);
row2.add(zero);
add(row2); 

GridLayout line3 = new GridLayout(3,2,2,2);
row3.setLayout(line3);
row3.add(add);
row3.add(subtract);
row3.add(multiply);
row3.add(divide);
row3.add(equals);
add(row3);

}


public void actionPerformed(ActionEvent event)
{

if (event.getSource ()== one)
{
resultField.setText( "1");
}
else if (event.getSource ()== two)

{
resultField.setText("2");
}
else if (event.getSource ()== three)

{
resultField.setText("3");
}
else if (event.getSource ()== four)

{
resultField.setText("4");
}
else if (event.getSource ()== five)

{
resultField.setText("5");
}
else if (event.getSource ()== six)

{
resultField.setText("6");
}
else if (event.getSource ()== seven)

{
resultField.setText("7");
}
else if (event.getSource ()== eight)

{
resultField.setText("8");
}
else if (event.getSource ()== nine)

{
resultField.setText("9");
}
else if (event.getSource ()== zero)

{
resultField.setText("0");
}
else if (event.getSource ()== add)

{
resultField.setText("+");
}
else if (event.getSource ()== divide)

{
resultField.setText("/");
}
else if (event.getSource ()== multiply)

{
resultField.setText("*");
}
else if (event.getSource ()== equals)

{
resultField.setText("=");
}
if (event.getSource ()== equals);
{

}
}

}