How do I synchronize a frame in the event dispatcher in java?

24 Views Asked by At

I created my own class to represent a menu that extends jFrame, I pass an enum to this class and based on the button that pushes the user in the related actionPerformed() methods I'm going to set the value of this enum; the problem is that being a thread it runs parallel to main, instead I would like to wait for the menu to finish to read the value of this enum variable and then decide what to do based on its value. Someone can help me?

public static void main(String args[]) {
        OptionEnum option = null;
        System.out.println(option+" in main");
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Menu(".//resources//img//sfondoMenuTheLastofUS.jpg", opzione).setVisible(true);
                } catch (ImgException ex) {
                    Logger.getLogger(Menu.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        /*try {
            new Menu(".//resources//img//sfondoMenuTheLastofUS.jpg", opzione).setVisible(true);
        } catch (ImgException ex) {
            Logger.getLogger(Menu.class.getName()).log(Level.SEVERE, null, ex);
        }*/
        
        System.out.println(option+" in main2");       
    }
0

There are 0 best solutions below