1
votes

Where it starts java.awt and public void run(), they are both underlined in red and when I click on them with my mouse, I get a message that says to move initializer to constructor. Can anyone help me with this?

public static void main (String[] args) {
    // TODO code application logic here
    EmployeeRecord main = new EmployeeRecord() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EmployeeRecord().setVisible(true);
            }
        )}
    }
}
1
Steve, thanks for the changes. I tried them and it didn't help. I have the correct brackets further down in my code.Alicia Hock

1 Answers

1
votes

Take out the wrapper. Below is all you need.

public static void main (String[] args) {

    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new EmployeeRecord().setVisible(true);
        }
    });    // <======= Notice the change here too. 
}

You just need to staticly call the method invokeLater of the EventQueue class. Doing what you're doing is a whole different (illegal) construct, which is not even possible. You are basically creating an anonymous class instance and in it you are calling the same constructor. Even if it was a correct construct like

public static void main (String[] args) {
    // TODO code application logic here
    EmployeeRecord main = new EmployeeRecord() {
        {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new EmployeeRecord().setVisible(true);
                }
            });
        }
    };
} 

you'd be creating an unnecessary instance.