Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need some calculation help

 
Stephenie Jannings
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment to make a calculator. This has to be done on a BorderLayout with a panel set to GridLayout. All that has been accomplished; however, to get the results to calculate is causing me great pain.
if(e.getSource()==b10)
total=(total*10)+8;
t.setText(""+total);
This is the code that I have for the numbers to appear. I need to somehow get the number that will be inputted to add, subtract, multiply, and divide another number that will be inputted.
Any suggestions will greatly be appreciated. Thanks
 
expired user
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a code for calculator whic i designed. Try this code and check out if it helps you.

(edited by Cindy to format code)
[ April 14, 2002: Message edited by: Cindy Glass ]
 
Jake Westphal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A note on OO design with regard to the code above, I read a good article about using inner classes to remove large switch or if/if else statements. It helped me understand good, real world uses for anonymous classes.
It would change the code above so that each button has its own implementation of actionPerformed, and thus, the large if/if statement in actionPerformed is not needed.
Here is the article:
Inner Classes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic