package gradertool.view; import javax.swing.*; import java.awt.*; import java.awt.event.*; import gradertool.gradebook.NewClassDisplay; import gradertool.gradebook.NewClassUI; /**** * * Class EditMenu is the "Edit" pulldown menu in the GraderToolUI prototype. * Anonymous instances of JMenuItem are defined for each item in the menu. *
* This class serves as a good example for how items are added to a menu, and * how an item's "action listener" is given a simple prototype implementation. *
* As explained in the Java Swing Tutorial, an action listener is implemented * in a method named "actionPerformed". This method is specialized for all * clickable GUI components, such as menu items and buttons. In a complete * implementation, action listeners perform actual computations, by calling * methods in companion computational classes. *
* In a GUI prototype, action listeners don't do any real work. Instead, they * do one of two things: *
* In the full implementation next quarter in 309, these simple prototype * actions will be replaced by calls to methods that do real work. * */ public class EditMenu extends JMenu { /** * Construct this by inserting each of its nine menu items into the * pulldown menu. The items are New, Open, Close, Close All, Save, Save * As, Save All, Print, and Exit. JSeparators are placed after the 'Close * All', 'Save All', and 'Print' items. */ public EditMenu() { super("Edit"); /* * Add each of the items to the menu, with separators in the * appropriate places (per the requirements). */ addUndoItem(); addRedoItem(); addCutItem(); addCopyItem(); addPasteItem(); addDeleteItem(); addSelectAllItem(); addFindItem(); } /** * Add the 'Edit' menu item. This and all other file menu items are created * using the following pattern: *
* JMenu.add(new JMenuItem("Item name")).addActionListener( * new ActionListener() { * public void actionPerformed(ActionEvent e) { * print a message to stdout, or bring up another GUI * } * } * ); **/ protected void addUndoItem() { /* * Use the standard menu item pattern for the item. */ add(new JMenuItem("Undo ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Undo selected."); } } ); } /** * Add the 'Redo ...' menu item. It just prints a message. */ protected void addRedoItem() { add(new JMenuItem("Redo ...")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Redo selected."); } } ); } /** * Add the 'Cut ...' menu item. It just prints a message. */ protected void addCutItem() { add(new JMenuItem("Cut")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Cut selected."); } } ); } /** * Add the 'Copy ...' menu item. It just prints a message. */ protected void addCopyItem() { add(new JMenuItem("Copy")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Copy selected."); } } ); } /** * Add the 'Paste ...' menu item. It just prints a message. */ protected void addPasteItem() { add(new JMenuItem("Paste")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Paste selected."); } } ); } /** * Add the 'Delete ...' menu item. It just prints a message. */ protected void addDeleteItem() { add(new JMenuItem("Delete")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Delete selected."); } } ); } /** * Add the 'Select All ...' menu item. It just prints a message. */ protected void addSelectAllItem() { add(new JMenuItem("Select All")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Select All selected."); } } ); } /** * Add the 'Find ...' menu item. It just prints a message. */ protected void addFindItem() { add(new JMenuItem("Find")).addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Edit->Find selected."); } } ); } }