Forums Register Login

Button number game problem

+Pie Number of slices to send: Send
I'm trying to make a click game. In the game, player must click at random placed numbers from 1 to 36(table 6x6). If player get wrong game will restart, if it's presed ok number will become X. On 1st click = No1, this click start the timer and when player click No36 stop the timer. This is the 1st frame, on second frame game display the time from 1 to 36 click. I tryed to made this game but I have a problem with aray of numbers. How to define that player must click from 1 to 36 by arow, and if get wrong restart game.
For now I have a frame with 36 buttons, timer, action listener, but I don't have an idea how to solve the problem.
Thanks in advance
+Pie Number of slices to send: Send
honestly...my advice would be to start over.

you should never write a line of code until you have thoroughly analyzed the problem, understand how to do everything, and thought through the best ways to do it. Writing code before figuring out all that will cause you no end of trouble.

So...forget about java for a while. figure out, in English (or any natural language you prefer) how YOU would do it. better yet, write down the steps as if you were telling a 8-yr old child how to do it. Once you have that done, writing the code usually follows pretty easy. If it doesn't, odds are you haven't refined your steps well enough to really explain what to do.
+Pie Number of slices to send: Send
Thanks, for answer. I'll try again. I am newbie in Java, and I'm trying to understand possibilities in resolving this problem.
+Pie Number of slices to send: Send
don't get me wrong...writing code is the best way to learn. Fred Brooks wrote in his book "The Mythical Man-Month" that you should "plan on writing one to throw away".

What he meant was that no matter how much planning you do ahead of time, when you really get down into it, when you actually start writing the code, you'll find all kinds of things you forgot to consider before you began, and will be hard to shoe-horn into what you have written to that point.

So don't delete what you wrote...just move it aside, reference it as you write you new code, and learn from what you've already done.
+Pie Number of slices to send: Send
Please Help. I made some changes in game. Now player have a frame with shuffled 36 numbers. Player must click on all 36 buttons from 1 to 36, and if get wrong buttons shuffled again. If player do as it must after the 36th click joptionpane give a massage of time between 1 and 36 click, that's all. After many corrections I made on game I am again on begining. Here is my code where I was stuck.



I can't get good shuffle collection for buttons with string on it, and than use action listener for string on button, then make array for if else, and that array compare with array of 1-36 and put else with shuffle again.
Can somebody give me a good example I have no time anymore. Must send for a 2 days.
Thanks
+Pie Number of slices to send: Send
I am not a GUI expert...but...i THINK your problem in in lines 35-40.

you create a new button with a label on 35, and assign it to your "button" reference. So button is pointing to a single object.

You then shuffle that one object, and then add it to your pane.


I think what you need to do is something like

+Pie Number of slices to send: Send
Thanks Fred, but that doesn't help me. I'm stil looking for solution, in the first line about shuffle. Then everything else.

In this solution NetBeans says me this: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 36

Thanks,

+Pie Number of slices to send: Send
Where is "the first line about the shuffle"? the code you posted compiles and runs.

An ArrayOutOfBounds exception is just what you'd think it is, based on its name. Java is telling you that you are trying to access the 37th element (index 36), but your array doesn't have that many elements.

I can't see where that would be happening, based on your code. Further, the error message tells you EXACTLY what line the error is occurring on.

So, without the actual code you are trying to run, and without the FULL error message, there is nothing I can do.
+Pie Number of slices to send: Send
Here is my code, and finally it works. I got random numbers, and action listener can recognize it. Now I need a help about actionlistener. How define the aray from 1-36, and if else restart JFrame? I looked for some sort of button++ solution, but I am green in Java for that. If someone know this kinde of solution I'll appreciate that.
Thanks in advance
+Pie Number of slices to send: Send
> Here is my code, and finally it works.

it's a bit rough, but it does display what you want.

seems this may be a learning exercise for others, so here's a working alternate version.
it's also a bit rough, but it might handle your latest query



[edit] typo fix
+Pie Number of slices to send: Send
Thank you very much, Michael. I got a clear view, now.
Climb the rope! CLIMB THE ROPE! You too tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3178 times.
Similar Threads
style, linking, adding, swing
Can someone test my game again?
why can't some people play my game
Head First Java: Guessing Game infinite look
OO design question?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:21:06.