Let us assume we have a simple Java MVC Application with the classes Model
, View
and Controller
. The View
class directly inherits from JFrame
. As in a classic MVC setup, the view has a reference to the model and the controller has a reference to the view and to the model.
As I just learnt, all GUI-related stuff should be wrapped in a SwingUtilities.invokeLater
or something similar. Now what is the right way to initialise/start this application? I think the creation of the model and the controller should not be inside of the EDT, right? So I would come up with something like this:
final Model model = new Model();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final View view = new View(model);
new Thread(new Runnable() {
@Override
public void run() {
new Controller(model, view);
}
}).start();
}
});
Is this the correct way and a good idea or are there better possibilities?
EDIT: As correctly stated by @trashgod, a related example is examined here. Then I extend my question: What is basically done there is the following:
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Model model = new Model();
View view = new View(model);
new Controller(model, view);
}
});
But isn't it wrong to run the whole application in the EDT?