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

Probably a simple answer

 
Ryan Perlman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a coinToss applet. I have got the applet written except I can't figue out how to get my (tails Field) tlsField, and my (heads Field) hdsField to keep a running count as you press the toss button. They keep reseting there values back to the initial value of 1. There is a Flip Field in the code that does nothing yet because I haven't written a method to set the field to true or false yet. should I do it as a boolean or just as a string?
Here is the code


(edited by Cindy to format code)
[This message has been edited by Cindy Glass (edited November 12, 2001).]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to create two variables that stores the coins count.
int headscounter = 0;
int tailscounter = 0;
These need to be initialized outside of your actionPerformed or they will reset to 0 everytime. Then, when a flip is decided, just increment one of the two variables.
headscounter++
or
tailscounter++


------------------
Happy Coding,
Gregg Bolinger
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic