I've been poking through the auto-generated code when making a new JFrame project with NetBeans, and came across this in my main
method:
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TestClass().setVisible(true);
}
});
After some reading I've come to understand the need for invokeLater so the GUI components are handled in the EDT. That said, the line new TestClass().setVisible(true);
, as it's implemented here, is a bit boggling to me. I get it in the context of creating a new instance...
TestClass tclass = new TestClass();
tclass.setVisible(true);
...but I don't quite follow what's going on in the run()
method above. Is that code creating an anonymous class? I've run across that term but don't fully understand it yet. I assume it's not creating an instance in the "textbook" way I listed above because there's no variable (that I can see anyway) to refer back to that instance.
As an aside, it seems to me having your main
method inside a JFrame class (or any GUI class, for that matter) isn't ideal anyway, so I'll probably move it.