creating a restart button help?

Maybe he’s a troll? ;D

He’s not
http://pastebin.java-gaming.org/28886830628
Just need “more” time to adapt ;D

OK everyone ! here is the link: http://pastebin.java-gaming.org/6368a201b27
Pestart JBar named “menu” doesnt work underneath the ActionEvent !

I think you should ditch the idea to restore all state.
Try to encapsulate your game in an own class so that you can create a game Object and connect it to the View(make your game class a Component and add it to a Panel).
When you achieved this you can just throw a game away and create a new one.

Your action method should be placed on JMenuItem rather JMenu. Declare one of that and put it to your “restart” JMenu.

Here’s some advice:

private String iconNames[] = {"D:/images/1.png", "D:/images/2.png", "D:/images/3.png", "D:/images/4.png"
                                    , "D:/images/5.png", "D:/images/6.png"};

Tip #1: never refer to files by their full path (i.e. including the D: part). If you do this, then the game will not work when you install it somewhere else.

if(e.getSource() == menu)

Tip #2: I’m not 100% sure but I think you should add a JMenuItem to the JMenu (e.g. a menu “Game” with an option “Restart”) for this to work. I’m don’t think JMenu generates action events. Read for example: http://stackoverflow.com/questions/9862165/jmenu-actionlistener

        th = new Thread(this);
        th.start();

This is a question, rather: why are you using a thread here? It looks risky.

This. I kinda overlooked your reply. ;D

Shall punish you! ;D Actually that’s his main prob.

private String iconNames[] = {“D:/images/1.png”, “D:/images/2.png”, “D:/images/3.png”, "D:/images/4.png"t
, “D:/images/5.png”, “D:/images/6.png”};
I know but this works well when it turns out to jar file, otherwise how could be restore images ? how about thread ? what else could be done by running time without using thread ? if there is another way to adapt this solution, how. I need to learn more about it

Don’t be strayed by that, focus on your prob. If it’s not broke no need to fix.

Agreed with ReBirth, don’t let me confuse you ;D The timer thing I’m not sure about myself, sorry for bringing that up. The images you can just put in the same (or a sub)directory of the jar file, e.g.:

game.jar
images/1.png
images/2.png

Then you can load the images using:

private String iconNames[] = {"images/1.png", "images/2.png", "images/3.png", "images/4.png"
                                    , "images/5.png", "images/6.png"};

Even when your game is on someone else’s computer, e.g. one that does not have D: But maybe you knew that already. :persecutioncomplex:

Hm. I always used an array of File objects, and then used getURI().

@ganaschka, why don’t you create a variable that holds either one or two ( or TRUE or FALSE) like so:


bool myrestart;
myrestart = true
// if button activates
myrestart = false;
while (myrestart = false){
//set all variable to 0
myrestart = true;
}
//go back to code
mycode()

And that only took me about 10 seconds 8)
(please check that the code syntax is correct ;D)