I am creating a simple text editor and have run into a small problem. I can open and have open several new windows for creating text documents by clicking on the new button in the menu. My problem is if I click on "File" then "Exit" from the menu it closes all the windows not just the one I wanted closed. How do I go about making it so that it will close just the chosen window and not the entire application.
Here's some code:
public void actionPerformed(ActionEvent event) {
if(event.getSource() == newFile) {
new EditorGUI();
} else if(event.getSource() == openFile) {
JFileChooser open = new JFileChooser();
open.showOpenDialog(null);
File file = open.getSelectedFile();
openingFiles(file);
} else if(event.getSource() == exit) {
System.exit(0);
}
}
It works however when I click on the X at the top right hand corner of the window:
private JFrame createEditorWindow() {
editorWindow = new JFrame("JavaEdit");
editorWindow.setVisible(true);
editorWindow.setExtendedState(Frame.MAXIMIZED_BOTH);
editorWindow.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// Create Menu Bar
editorWindow.setJMenuBar(createMenuBar());
editorWindow.add(scroll, BorderLayout.CENTER);
editorWindow.pack();
// Centers application on screen
editorWindow.setLocationRelativeTo(null);
return editorWindow;
}
Screenshot: