• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI Restart Button Help  RSS feed

 
Alexander Vinogradov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guy would really appreciate it if somebody could tell me how to make this restart button work. This is what I have so far. I have put the restart button code in red and bold...



package Game;

/**
*
* @author Sasha
*/
public class Buttons extends javax.swing.JPanel {

private GameWorld world;
private int restart;


public Buttons() {
restart = 1;
world = new GameWorld();


}

public Buttons(GameWorld world) {
this.world = world;
initComponents();
}

@SuppressWarnings("unchecked")


private void QuitButtonActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

private void PauseButtonActionPerformed(java.awt.event.ActionEvent evt) {
world.setPaused(true);
}

private void PlayButtonActionPerformed(java.awt.event.ActionEvent evt) {
world.setPaused(false);
}

private void RestartButtonActionPerformed(java.awt.event.ActionEvent evt) {
restart++;
world.start();
world = new GameWorld();


}


private javax.swing.JButton PauseButton;
private javax.swing.JButton PlayButton;
private javax.swing.JButton QuitButton;
private javax.swing.JButton RestartButton;




}
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why are you creating a new Game object after the start() call? What does start() do?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and welcome to the 'Ranch!
Just a quick tip for future reference, if you're going to post some source code you should put it between code-tags, so it looks like this:

You can use the Code button in the Reply editor to add them, or manually: [code=java][/code]
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have added code tags, only the code was not indented, so the benefit would not have been so obvious.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!