• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GUI Restart Button Help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;




}
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic