Reputation: 11
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);
}
)}
}
}
Upvotes: 1
Views: 2443
Reputation: 209132
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.
Upvotes: 1