Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Button receive an sum  RSS feed

 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I'm doing an calculator on Java.
But, when the user press the button 1 (one). The Button receives the sum.
For example:



Thanks you!
 
Devaka Cooray
Marshal
Posts: 5322
575
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please TellTheDetails ? What did you mean by "Button receives the sum" ?
 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
Sorry.
I'm creating an calculator on Java. The Button 1, will receveis an sum. However, I trying so:



But, I don't I'm achieving do the sum.

After this, the user will select the button the which want do the sum with other number. For example: 2
 
Devaka Cooray
Marshal
Posts: 5322
575
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to give you a reasonable answer without knowing how you made your buttons to trigger the ActionListener, and the logic you used in actionPerformed. Is that String sum = "+"; the only statement exist in your actionPerformed method? Also how did you assign your action listener(s) to the buttons?
 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright. See other logic for the problem:



But, see the error:

 
Devaka Cooray
Marshal
Posts: 5322
575
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The expression i<=numbers.length causes that exception. If you use <= operator, the length, which is 10, will also be assigned to i at the last iteration, which is beyond the scope of the array [0...9]. Replace <= with < and it should work fine. Is this the same problem you were trying to describe before in this topic?
 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Why, the my logic presented here, no will success!
Thanks you by help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!