• 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

Java GUI counter problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am developing a GUI and one of my counter keeps incrementing by 16 each time the user wins? Ill post my code below.


The counter to count how many plays increments by 1 each time but the winCount incrememnts by 16 each win? Both are set to 0 at the top of the class. Thanks for any help!
 
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

one of my counter


Could you give the name of the variable you are talking about?
Also try debugging the code by adding a print statement that prints the value of the variable every time its value is changed.  The print out should help you find the problem.
 
Norman Radder
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I see the names at the end of post.  Add the print statement to show what is happening.
 
Bryan Barrett
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks for reply since i posted i have changed to just count the times played and times played each week and it counts properly. I am now having difficulty for handling the exceptions. For example,


I am extremely new to exception handling and wondering why this doesnt work, i have also used Exception e instead of NumberFormatException e. I am trying to display that message if the user presses reset and no numbers are entered. If  no numbers are entered the numberSelection arrayCount is at 0, so i am confused as why it does not run?
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Bryan Barrett wrote:. . .. . .

That bit doesn't look right to me. It looks a bit like what I said in this old thread (the whole thread is worth reading) and that line will reliably create a randomly‑chosen number from the range 1...1
I prefer using a Random object to doing arithmetic with Math#random and I disagree with this part of the Java™ Tutorials. I wold use Math#random only if I want a number x • x ≥ 0 ∧ x < 1.0.
 
Bryan Barrett
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, don't worry i had it set to 1 for testing purposes only!
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a pleasure but consider using a Random object for better reliability. And if you write 1 in your code, we'll believe you
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic