1

I'm coding a bet system to texas holdem and i have problem with opening all windows at once.

while (rozdania > 0){

        for(Player p : pp){
            if(p.inGame()){
                pula+=p.bidWindow();
            }
        }

        rozdania--;
    }

public int bidWindow(){
    new WindowBid(this);


    return 1;

}

public WindowBid(Player p){
   setDefaultCloseOperation(EXIT_ON_CLOSE); 
   setSize(400,175);
   setVisible(true);

}

I want to open windows right after when the previous was closed. But i have no idea how to do it.

I'm using JFrame for that. (Sorry for my English tough)

Thanks.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Kenik
  • 103
  • 1
  • 15
  • 1
    Please have a look at [The Use of Multiple JFrames: Good or Bad Practice?](https://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-or-bad-practice) to see why you may want to change and improve your current user interface structure. – Hovercraft Full Of Eels Aug 01 '17 at 17:27
  • But most importantly the loop structure should not be used for data intake in an *event-driven* GUI program. Instead you would react to events, perhaps windows listener events, or button press (ActionListener) events, and change program behavior based on the event and the program's current state. – Hovercraft Full Of Eels Aug 01 '17 at 17:28

1 Answers1

0

You can open a new window on the close event by using a WindowListener or WindowAdapter.

The code might be something like this:

WindowAdapter adapter = new WindowAdapter(){
    void windowClosed(WindowEvent e){
        //open next window.
    }
}

jFrame.addWindowListener(adapter);

I'd then suggest placing the parameters for the windows that you want to open in some sort of queue, and on each windowClosed event, you will pop the next window parameters from the queue and initialize it.

Christopher Schneider
  • 3,745
  • 2
  • 24
  • 38