Programming Assignment 5
A Simple Text Editor using Java Swing
Code Review for Jade Cheng
Build Results
No errors; no warnings
Requirements Verification
All source code should be submitted in one file, and that file should be named according to the following pattern: LastFirstX.java
, where Last
is the student’s last name, First
is the student’s first name, and X
is the assignment number.
For example, student John Doe
would submit DoeJohn3.java
for programming assignment 3.
PASS.
The first lines of the submitted file should include a comment with the following information and format:
/** * A short description of the program. * * @author Last Name, First Name * @assignment CSCI 2912 Assignment X * @date Date */
PASS.
The submitted file should be emailed to ycheng@hpu.edu.
PASS.
The subject line of the email sent to the instructor should follow the pattern: [2912] assignment number
.
For example, for assignment 3, student John Doe would write “[2912] assignment 3
” as the subject line of his submission email.
PASS.
The submission email sent to the instructor should include exactly one attachment, the Java implementation file. Students should not attach any other files to their submission email.
PASS.
The implementation file must include JavaDoc for all definitions: classes, interfaces, fields, methods, enumerations, and so on.
PASS.
You will implement a Java Swing application that allows the user to open, edit, and save text files.
PASS.
When the application starts, it displays a JFrame (window) that is centered both horizontally and verticallty on the screen.
PASS.
The application allows the user to move and resize the window using the standard controls provided by the host operating system.
PASS.
Initially, the title of the window is “Untitled - CSCI 2912 Editor”.
PASS.
When the window is closed, the application terminates.
PASS.
The application sets the content area of the window to a JScrollPane
.
PASS.
The initial size of the scroll pane is 500x500 pixels.
PASS.
When the window size changes, the scroll pane stretches to fill the entire bounds of the content area.
PASS.
The application adds to the scroll pane an editable JTextArea
.
PASS.
The text area displays text with a 14-pt “Monospace” font.
PASS.
The text within the area is left justified and does not wrap automatically.
PASS.
When the size of the scroll pane changes, the text area stretches to fill the entire bounds of the scroll pane.
PASS.
If the size of the text exceeds the size of the scroll pane, horizontal or vertical scroll bars appear that allow the user to scroll through the text area content.
PASS.
The application displays a JMenuBar
.
PASS.
The menu bar contains one JMenu
with the text “File”.
PASS.
The application uses the letter “F” as the mnemonic for the File Menu.
PASS.
Hint: When hosted on Mac OS X, to cause the Menu Bar to appear at the top of the screen, set the system property “apple.laf.useScreenMenuBar” to “true”. Setting this property on Windows or Linux hosts has no effect.
PASS.
The File Menu contains five JMenuItem
instances; ordered from top to bottom, the names of these items are “New”, “Open”, “Save”, “Save As...”, and “Exit”.
PASS.
The application adds a separator between the Open Menu Item and the Save Menu Item, and it adds another separator between the Save As... Menu Item and the Exit Menu Item.
PASS.
The application assigns mnemonics to all menu items.
PASS.
The application assigns accelerators to all menu items except the Exit Menu Item.
PASS.
The mnemonics and accelerators are defined in the table below.
PASS.
The application determines the appropriate shortcut key using the Toolkit.getMenuShortcutKeyMask
method.
PASS.
When the user selects the New Menu Item, the application clears the text shown in the text area.
PASS.
The application then sets the title of the window to “Untitled - CSCI 2912 Editor”.
PASS.
When the user selects the Open Menu Item, the application shows an Open File dialog using JFileChooser
.
PASS.
If the user selects a file from this dialog, the contents of the text area is replaced by the contents of the file.
PASS.
The application then sets the title of the window to “XXX - CSCI 2912 Editor”, where “XXX” is the name of the file not including its directory.
PASS.
If an I/O error occurs while opening or reading the file, the application does not clear the contents of the text area or change the title of the window but instead displays an error dialog using JOptionPane.showMessageDialog
.
PASS.
The application sets the title of this dialog to “Error Opening File”, the message type to JOptionPane.ERROR_MESSAGE
, and the message text itself to the value returned by Exception.getMessage()
.
PASS.
When the user selects the Save Menu Item before successfully opening or saving the file since the time the application was started or since the user selected the New Menu Item, then the application proceeds as if the user selected the Save As... Menu Item.
PASS.
Otherwise, the application saves the contents of the text area to the path most recently selected by the user.
PASS.
If an I/O error occurs while recreating or writing to the file, the application displays an error dialog using JOptionPane.showMessageDialog
.
PASS.
The application sets the title of this dialog to “Error Saving File”, the message type to JOptionPane.ERROR_MESSAGE
, and the message text itself to the value returned by Exception.getMessage()
.
PASS.
When the user selects the Save As... Menu Item, the application shows a Save File dialog using JFileChooser
.
PASS.
If the user selects a file path from this dialog, the contents of the text area are written to the path selected by the user.
PASS.
The application then sets the title of the window to “XXX - CSCI 2912 Editor”, where “XXX” is the name of the file not including its directory.
PASS.
If an I/O error occurs while creating or writing the file, the application does not change the title of the window but instead displays an error dialog using JOptionPane.showMessageDialog
.
PASS.
The application sets the title of this dialog to “Error Saving File”, the message type to JOptionPane.ERROR_MESSAGE
, and the message text itself to the value returned by Exception.getMessage()
.
PASS.
When the user selects the Exit Menu Item, the application terminates.
PASS.