This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Applets and the fly likes GUI  calculator applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "GUI  calculator applet " Watch "GUI  calculator applet " New topic
Author

GUI calculator applet

Charles Woods
Greenhorn

Joined: Jun 04, 2007
Posts: 7
I am a newcomer working on a calculator applet.

What I KNOW how to do:
create buttons and JComponents

What I DONT KNOW yet:
how to create algorithmic functions within the applet and have the sums, differences, products, and quotients show up on the JTextArea or JTextFrame.

Thanks for the help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42359
    
  64
There's a number of things you'll need to get right. I'll just list a few you will need to look into (not necessarily in this order):
  • You can retrieve the values from a JTextField or a JTextArea using the getText method. getText returns a String; you can use Double.parseDouble to convert that to a number. (Since you're building a calculator, I think it would be more natural to use JTextField, not JTextArea).
  • You can set the value of a JTextField using the setText method. A number can be converted to a String by prepending the empty string to it, like ""+3.5 .
  • You'll need to keep track of where you are in the sequence of keystrokes. E.g. if the user just clicked the plus button, you'll need to store the current value of the display somewhere, remember that the operation to be done once "=" is clicked is addition, and clear the display as soon as the next digit is clicked.

  • Does this help? Or am I misunderstanding where you're stuck?


    Ping & DNS - my free Android networking tools app
    Charles Woods
    Greenhorn

    Joined: Jun 04, 2007
    Posts: 7
    I haven't tried your advice yet, but it sounds like the best I have received. I'll let you know when I get it right. Thanks.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: GUI calculator applet