• 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

GUI Buttons Help

 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below GUI code is a simple scorekeeping program. The problem is the buttons. They're not working like they should. You'll understand when you run it. I used the NetBeans GUI maker for this; I'm not an experienced programmer. I've only had one year of Java in school. Anyways, it would be nice if you could change it / tell me what to change. Thanks

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. I really didn't want to download your code and look for bugs which were too complicated to be described in a forum post. So I just browsed the code looking for things which might be wrong. I did find this:

It seems to me that something which is supposed to be adding 10 to Team 2's score shouldn't be starting from "team1Score".

However if that isn't what you had in mind, then I would recommend you spend a couple of minutes to figure out what your problem is and to post an explanation of the problem. What happens, when does it happen, and what should happen instead?
 
Joel Christophel
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:
What happens, when does it happen, and what should happen instead?



Sorry, I should've been more detailed. And thanks for pointing out that error. (The making of sloppy copy-pasting)

When I press a button, Ex: "+10", it will change the score to 10. That's fine and dandy, but when I click the button again, the score doesn't change. If I would then click "+5", the score would just change to 5. So basically, there is no addition or subtraction happening. Or if there is, it is just adding or subtracting from 0 and not the previous number.

What should happen instead? Clicking "+5", then "+10", then "+10", then "-5", and then "-5" should result in the displaying of the number 15 instead of -5 (the last number pressed).

I hope that cleared things up.
-Joel Amos Christophel
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that you set the label's text to "team1Score + 10", but you never set "team1Score" to anything other than 0, so it remains 0, and scores don't accumulate. You'll want to do something like


 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swing is pretty easy to learn and code "by hand." The Netbeans GUI Builder creates complicated code that is nearly impossible for a human to read, making the resulting code difficult or impossible to modify, reuse, and maintain. I recommend you learn to code Swing yourself. There are excellent tutorials available for free, and there is always help available.

Good luck.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ernest Friedman-Hill Yup, that would be precisely the problem. Thanks for helping. =)
@Greg Brannon I would learn it, except that 1) I don't feel like my knowledge of the basics if firm enough yet and 2) I only wish to make one GUI program for now and for a specific purpose, so it seems kind of useless to learn lots more things for one specific occasion

Thanks all!

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Greg Brannon. The approach of "I only need it this once" will result in your never learning to do it right. You should of course start with the basics, and learn slowly, starting with simple things.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic