0

I'm making a simple card game with play chips. I have a Launcher class with a JFrame and an actual Game class with a JFrame. The Launcher runs and has a play button. So after every round, the Game JFrame disposes, and adds the chips to the Player's balance, which is displayed on the Launcher. The problem being that the Launcher displays the starting balance, not the balance post-game.

I was wondering if for every instance of game.dispose() if I can tell the Launcher to update the Balance to the player's new total.

Bryan
  • 43
  • 8
  • Could you post some parts of the code? It's difficult to understand what's wrong: where do you store the "balance", what do you mean by "Launcher", etc. – Matthieu Apr 26 '16 at 16:24
  • 1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Apr 26 '16 at 17:15
  • Don't use multiple frames; Use a `CardLayout`; Use a dialog; Use an observer pattern ... just a few ideas – MadProgrammer Apr 26 '16 at 21:38

1 Answers1

-1

Yes.

Add a Launcher property to the game class and set it to the instance of the launcher. Before exiting the game frame call a method to update the chip numbers in the launcher class.

public class Game {
     ....
     private Launcher l;

     public Game(Launcher l) {
        this.l = l;
        .....
     }

     public void dispose() {
         l.setChips(chipTotal);
         ....
     }
}
B. Paske
  • 14
  • 2