• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Button receive an sum  RSS feed

 
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!
 
Marshal
Posts: 6076
965
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: 6076
965
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: 6076
965
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!