Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified SimpleJavaTextEditor.jar
Binary file not shown.
14 changes: 10 additions & 4 deletions src/simplejavatexteditor/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
package simplejavatexteditor;

import java.lang.reflect.Method;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
Expand Down Expand Up @@ -506,13 +507,17 @@ else if (e.getSource() == newFile || e.getSource() == newButton) {
} // If the source was the "open" option
else if (e.getSource() == openFile || e.getSource() == openButton) {
JFileChooser open = new JFileChooser(); // open up a file chooser (a dialog for the user to browse files to open)
if( !(textArea.getText().equals("")) ) {
saveFile();
}
// if true does normal operation
int option = open.showOpenDialog(this); // get the option that the user selected (approve or cancel)

/*
* NOTE: because we are OPENing a file, we call showOpenDialog~ if
* the user clicked OK, we have "APPROVE_OPTION" so we want to open
* the file
*/
* NOTE: because we are OPENing a file, we call showOpenDialog~ if
* the user clicked OK, we have "APPROVE_OPTION" so we want to open
* the file
*/
if (option == JFileChooser.APPROVE_OPTION) {
FEdit.clear(textArea); // clear the TextArea before applying the file contents
try {
Expand All @@ -529,6 +534,7 @@ else if (e.getSource() == openFile || e.getSource() == openButton) {
System.err.println(ex.getMessage());
}
}

} // If the source of the event was the "save" option
else if (e.getSource() == saveFile || e.getSource() == saveButton) {
saveFile();
Expand Down