This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes A simple calculator help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A simple calculator help!" Watch "A simple calculator help!" New topic

A simple calculator help!

Bo Gambles

Joined: Mar 27, 2006
Posts: 14
Hello again

I've got a quick calculator that I wanted to create, but I seem to be having more troubles with it than I expected

But I'm having troubles doing the calculation. I can't get the String A number to recall it in the equals part. I'll be extremly grateful if someone could clean the code up if they have the time, or give me a general code that I can use to do the calculation.

If this isn't possible, could anyone give me examples of some REALLY basic and simple calculator code, thanks
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41092
In your handlers for add, minus and multiply you have lines like

int firstInput = Integer.parseInt(aTextField1.getText());

That "int" in front of it should not be there. You're declaring a new variable firstInput, which hides the field of the same name. Thus the newly entered value is never stored in a place where the code can get at it.

Ping & DNS - my free Android networking tools app
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802 should only have one listener for all those buttons..

just do an if - else statement..

like so

public class listener implements ActionListener
public void actionPerformed(ActionEvent event)
if(event.getSource() == one)

if(event.getSource() == two)

//and so on




You down with OOP? Yeah you know me!
Don't get me started about those stupid light bulbs.
subject: A simple calculator help!
Similar Threads
A calculator question!
Adding .binary and hexidecimal to an answer from a calculation
Simple: Turning A Program Into An Applet
Calculator Problem
Can't Update Record ?