import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

public class FreezePleeze {

    public static final Object[] ALL_THE_SINGLE_LADIES = {"Rahan", "Crao", "Naouna", "Han-ra"};

    public static void main(String[] args) {
        new FreezePleeze();
    }

    public FreezePleeze() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JButton push_me = new JButton("Push me");
                JFrame frame = new JFrame("Mmmmm");
                JPanel containerPanel = new JPanel();
                frame.add(containerPanel);
                final JComboBox<Object> comboBox = new JComboBox<>(ALL_THE_SINGLE_LADIES);
                containerPanel.add(comboBox);
                frame.setSize(300, 300);

                comboBox.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JDialog jDialog = new JDialog((JFrame) null, true);
                        jDialog.add(push_me);
                        if (comboBox.getSelectedIndex() == ALL_THE_SINGLE_LADIES.length - 1) {
                            jDialog.setLocationRelativeTo(frame);
                            jDialog.setSize(300, 300);
                            jDialog.setVisible(true);
                        }
                    }
                });

                comboBox.addPopupMenuListener(new PopupMenuListener() {
                    @Override
                    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    }

                    @Override
                    public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                        try {
                            Robot robot = new Robot();
                            robot.keyPress(KeyEvent.VK_WINDOWS);
                            robot.keyRelease(KeyEvent.VK_WINDOWS);
                        } catch (AWTException e1) {
                            e1.printStackTrace();
                        }
                        push_me.setText("Finished counting");
                    }

                    @Override
                    public void popupMenuCanceled(PopupMenuEvent e) {
                    }
                });
                frame.setVisible(true);
            }
        });
    }
}