Q:

Swing Countdown from 5 to 0

I am creating a Java Swing game and before every new game I would like to have a frame show up and countdown from 5 to 0 seconds. 
While this is happening I would like the game in the background to wait until the countdown is complete.  What would be the best way to make the game in the background wait?  
I have tried Thread.sleep but this causes the The Event Dispatch Thread to sleep and the GUI not to update.  However, it works the first time i run it but not the second. 
Thankful for your help. 
public class CountdownPresenterPanel {
    JFrame mainFrame;
    int currentNumber = 5;
    JLabel textLabel;

    CountdownPresenterPanel() {
        mainFrame = new JFrame();
        textLabel = new JLabel(String.valueOf(currentNumber), SwingConstants. CENTER);
        textLabel.setFont(new Font("Arial", Font. BOLD, 55));
        textLabel.setVerticalAlignment(SwingConstants. CENTER);
        mainFrame.add(textLabel);
        mainFrame.setUndecorated(true); // Remove bar including close, minimize
        mainFrame.setSize(600,300);
        mainFrame.setLocationRelativeTo(null);
        mainFrame.setVisible(true);
        Timer timer = new Timer(1000, new ActionListener() { 
            @Override
            public void actionPerformed(ActionEvent e) {
                if(currentNumber > 0) {
                    currentNumber--;
                    textLabel.setText(String.valueOf(currentNumber));
                } else {
                    mainFrame.setVisible(false);
                    mainFrame.dispose();
                }
            }
        });
        timer.setRepeats(true);
        timer.start();
    }
}

Solution
import java.awt.*; 
import java.awt. Font;
import java.awt.event. ActionEvent;
import java.awt.event. ActionListener;
import javax.swing. JDialog;
import javax.swing. JLabel;
import javax.swing. SwingConstants;
import javax.swing. Timer;

public class CountdownPresenterPanel {
    private int currentNumber = 5;
    private JLabel textLabel;
    private final JDialog dialog;
    CountdownPresenterPanel() {
        Timer timer = new Timer(1000, new ActionListener() { 
            @Override
            public void actionPerformed(ActionEvent e) {
                if(currentNumber > 0) {
                    currentNumber--;
                    textLabel.setText(String.valueOf(currentNumber));
                } else {
                    dialog.dispose();
                }
            }
        });
        Frame window = new Frame();
        dialog = new JDialog(window, "Alert", true);
        textLabel = new JLabel(String.valueOf(currentNumber), SwingConstants. CENTER);
        textLabel.setFont(new Font("Arial", Font. BOLD, 55)); // Increase the font-size
        dialog.add(textLabel);
        dialog.setSize(400, 200);
        dialog.setLocationRelativeTo(null);
        timer.setRepeats(true);
        timer.start();
        dialog.setUndecorated(true);
        dialog.setVisible(true);
    }
}

A:

Don't use a JFrame, use some kind of modal dialog
Take a look at How to Make Dialogs for more details

