• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI calculator applet

 
Charles Woods
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic