You might want to use a switch statement to alternate between your keys.If your calculator GUI has a textfield, which will be the only textfield.Create the methods for add,minus,multiply and divide,do your calculations in this methods by getting the value from the textfield,then in your case:key(specify the key to be pressed) call the methods you have created. I hope this will help.Feel free to reply if you are still confused. Good luck.
Here's a neat trick. Build the calculator first without the GUI and just drive it with a test program.
Then when you build your GUI it's obvious what each button listener has to do - just send the text from the button to the calculator.
This test program asks for the answer. Making the answer pop into the results box is a different scheme, probably involving a call back or listener.
Show us what you've made so we can see where you're stuck and try to get you going again.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Nov 11, 2006
this is the Calculator code that i developed, the GUI was not perfectly arranged as i wanted but still contains all neccessary components that i needed. My main problem now is to get those buttons working and i will later learn more about my Layout manager.
Look into the concept of "action listeners", which are callback methods that get invoked when a button is clicked, so that the application can react to the button click. The Sun Java tutorial has a section on this.
Ping & DNS - updated with new look and Ping home screen widget