jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Applets
Bookmark "GUI  calculator applet " Watch "GUI  calculator applet " New topic

GUI calculator applet

Charles Woods

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

Joined: Mar 22, 2005
Posts: 42965
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?
    Charles Woods

    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
    It's not a secret anymore!