Forums Register Login

A calculator question!

+Pie Number of slices to send: Send


This is part of my calculator I'm trying to create. What i want to do is have the text field display the numbers which are being enterested into a the applet, and for them to be either added, multiplied, divided etc. So for example if a user wanted to add 120 to 120 they'd see "120 + 120" as the request, then the answer will be shown as "120 + 120= 240".

How will this be possible from here? All replies will be duely greatful from me, thanks

What I'm trying to do it
+Pie Number of slices to send: Send
Welcome to JavaRanch.

So what does this code do, then? If it doesn't do what you describe, tell us what it does, and what you're having problems with. Then we can try to help you get going again.
+Pie Number of slices to send: Send
Basically so far it has initiated buttons 0-9 with values, it also has given a clear function

The next part I want it to do is have some sort of key listener to allow multiple presses to bring up multiple numbers, because right now its brining up an int, and then it is just deleting the int when the secogn number is entered. For example it if I press button 1, it will show number one, but if I press button 2 it will clear the original number and then replace it with the number 2

Basically I want to make a simple calculator with key presses from the Jbuttons, but its working out to be a little hard
+Pie Number of slices to send: Send
Instead of writing

aTextField1.setText("3");

you should do something like

aTextField1.setText(aTextField1.getText()+"3");

That way the previously entered text will be preserved.
+Pie Number of slices to send: Send
^^Thanks for that reply, I'm out of the labs right now but I will try it later today.
+Pie Number of slices to send: Send
Hi, its me again!

Now I have the buttons and the text fields sorted out, but now I need to allow the buttons to do their calculations. Thats what Im having troubles with

Any help? Thanks
+Pie Number of slices to send: Send
Bo, Gambles,
I am also creating calculator, and I have the same, almost the same problems.
You know, my problem is that these buttons that I'm telling get String, I mean, I say if you press that button, set Text "1". So, "1" is string, and I don't know how to make this string double. I did Double.toString and Double.parseDouble to convert it, but it says that it cannot be applied to Buttons.



How are you going to deal with this problem?

Please, help us!!!
+Pie Number of slices to send: Send
Bo, Gambles,
I am also creating calculator, and I have the same, almost the same problems.
You know, my problem is that these buttons that I'm telling get String, I mean, I say if you press that button, set Text "1". So, "1" is string, and I don't know how to make this string double. I did Double.toString and Double.parseDouble to convert it, but it says that it cannot be applied to Buttons.



How are you going to deal with this problem?

Please, help us!!!
+Pie Number of slices to send: Send
I think you need to use a double.parsedouble(getText) and use that where you what to get your double from. You cant change a string into a double not using a parse, as far as Im aware
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 959 times.
Similar Threads
Calculator Problem
A simple calculator help!
deal with text on window closing
Adding .binary and hexidecimal to an answer from a calculation
Game GUI
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:32:33.