File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jbutton problem

 
James Smith
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im reading the dietel java book right now. On chapter 6 theres an example using a jbutton in a game of craps. The action listener is applied to the jbutton.
My problem is this:
in the actionlistener method, the first line is if (firstroll)
call rolldice();
firstroll was initialized in the class as a boolean set = true
the book explains it as true means its the start of a new game, and false means continue the game.
is this the regular technique of utilizing jbuttons? with a booleans true/false way of doing things?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, no. I have NEVER used a boolean check in the action of a button. However, I have never had a GUI that had to know if this was the FIRST time the button was pushed or not. My buttons have all done the same thing no matter how many times that you pushed them.
That is just a bit of logic that was used because of the scenario.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this the regular technique of utilizing jbuttons? with a booleans true/false way of doing things?
I have seen many new programmers control the flow of a program using such a technique. I'm sure I did so when I wrote my first few game Applets. As I read more and wrote more programs and asked and answered more questions here at JavaRanch, I learned better/different ways to control the flow of a program.
 
Robbie shi
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you show your code
?
i want to check it
--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
-----------------------------
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic