• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calc with Events - Help !!

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ppl!
I really need help.I need to write a code for a calculator,something like the one used in windows.How do i do mathematical equations (for examp 3+2*5 - in the right order!) if the entered numbers are from buttons pressed (something to do with getActionCommand() ??).
Thanx sooo much,
Shusha.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most calculators that I know expect the user to enforce the order of execution by providing temporary memory areas that the user can store an intermediate result to. If they do NOT choose to use that option, then the calculator executes the operations in the order that they are entered, and displays the intermediate results along the way.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
When a button is pressed, an action event is generated. Just trap that ActionEvent by providing an ActionListener. Check the component that generated the event( if (event.getSource() == button_1) ) and do the calculations based on the event source.

Hope this helps.
Ashwin.
 
Shusha Tedi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey again,
Thanx so much 4 ur help!
I dont understand 1 thing,the calc - when i press a button i generate an event which in this case presents what i pressed in the textfield.How can i use the buttons to do a mathematical equation ? like there type is Button,how do i do button_1 add button_2 equals(=) ... ?? (Without having to cast there type).
Thanx again,u guys r great.
Shusha Tedi.
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic