File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes jbutton problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "jbutton problem" Watch "jbutton problem" New topic

jbutton problem

James Smith

Joined: Dec 19, 2002
Posts: 12
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"

Joined: Sep 29, 2000
Posts: 8521
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.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Robbie shi

Joined: Jan 05, 2003
Posts: 28
can you show your code
i want to check it
----------------------------- IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
I agree. Here's the link:
subject: jbutton problem
It's not a secret anymore!