• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

GUI calculator applet

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    What a show! What atmosphere! What fun! What a tiny ad!
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic