I am trying to learn the intricacies of Swing, and have read a great deal about the Event Dispatch Thread. I understand what is for, however am struggling with the following concept:
I have a JFrame which has been invoked in the normal way:
public class Controller {
GUITopLevel gui = new GUITopLevel(this);
public void initiate() {
SwingUtilities.invokeLater(
new Runnable() {
@Override
public void run() {
gui.init();
}
}
);
}
public void menuCatch(JMenuItem eventSource) {
JOptionPane.showMessageDialog(gui.topLevelFrame, eventSource.getActionCommand());
}
}
I want to spawn JDialogs from the gui (code thus):
public class GUITopLevel implements FrontOfHouse {
JFrame topLevelFrame;
Controller control;
GUITopLevel(Controller c) {
control = c;
}
@Override
public void GUI() {
// Create an action
MenuAction action = new MenuAction(control);
// Create the Frame
topLevelFrame = new JFrame();
// Create the menu bar
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu("File");
JMenu edit = new JMenu("Edit");
JMenuItem file1 = new JMenuItem();
JMenuItem file2 = new JMenuItem();
JMenuItem file3 = new JMenuItem();
JMenuItem edit1 = new JMenuItem();
// Set the actions
file1.setAction(action);
file2.setAction(action);
file3.setAction(action);
edit1.setAction(action);
// Add the menu items
file.add(file1);
file.add(file2);
file.add(file3);
edit.add(edit1);
// Set the text
file1.setText("Import Diagrams");
file2.setText("Settings");
file3.setText("Exit");
edit1.setText("Cut");
// Add the menus together
menuBar.add(file);
menuBar.add(edit);
// Set size and add menu bar
topLevelFrame.setSize(600,400);
topLevelFrame.setJMenuBar(menuBar);
topLevelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void init() {
GUI();
//topLevelFrame.pack();
topLevelFrame.setVisible(true);
}
}
When a menuitem gets clicked, this is called in the controller:
public void menuCatch(JMenuItem eventSource) {
JOptionPane.showMessageDialog(gui.topLevelFrame, eventSource.getActionCommand());
}
As gui is the parent container for the JOptionPane, and that has been created with an invokeLater, does this mean that the newly spawned JOptionPane has been called on the EDT or has it been called outside the EDT?
Apologies if this is a duplicate -- I can not seem to find an answer to this question.