• 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

Probably a simple answer

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic