Hi, I sorted out all the problems above thanks to the thread, but I have come up with a new problem. Basically, on the equals button I'm trying to tell it to either add, multiply, divide or minus.
So say if the user presses multiply the clocker will then equal 3..So when the equals button is pressed, it will look through the if statements till it gets to 3 and then do the required sum
**at the very top of my code*
aButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
firstInput = Integer.parseInt(aTextField1.getText());
clocker = 1;
aTextField1.setText("")
;}
});
aButton2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
firstInput = Integer.parseInt(aTextField1.getText());
clocker = 2;
aTextField1.setText("")
;}
});
aButton3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
firstInput = Integer.parseInt(aTextField1.getText());
clocker = 3;
aTextField1.setText("")
;}
});
aButton4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
firstInput = Integer.parseInt(aTextField1.getText());
clocker = 4;
aTextField1.setText("")
;}
});
clear.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent c)
{
aTextField1.setText("");
zero.setPreferredSize(new Dimension(x, y));
}
});
equals.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent c)
{
secondInput = Integer.parseInt(aTextField1.getText());
if (clocker == 1)
{
sum = firstInput + secondInput;
String hi = new String (firstInput + "+" + secondInput + "=" + sum);
aTextField1.setText(hi);
}
if (clocker == 2);
{
sum = firstInput - secondInput;
String hi = new String (firstInput + "+" + secondInput + "=" + sum);
aTextField1.setText(hi);
}
}
});
}
}
But I keep on getting the folowing error of sum..
I know what a boolean is, but I thought that it didn't need to be used here. If it does, could anyone point me out on how to do it depending what operator buttin was pressed
Thanks