EE408 Lab 4: Enhancing the First GUI Application
3% (0.5% for each of 1-4, 1% for 5)
Due: 5
PM, Friday September 19.
Note.
new deadline: 5 PM, Monday September 22.
The objective of this lab exercise is to add additional elements to the
GUI application we created during this week to make it fuller and
closer to be a real application. To ensure that we all start on the
same technical basis, my copy of the application will be emailed to you
before the lab starts.
1. Menu
Make three top-level menus, from left to right: File
Edit
Help
Rather than next to Edit, Help should be moved to the far
right of the menu bar. (How
to Use Menus contains instructions on how to do this.)
File menu should contain New,
Open ..., Email, and Save as submenus, in this order. Add
a separator between Email and Save.
Edit should contain Redo, Undo, Cut, Copy, and Paste as submenus, in this order.
Help should contain About ... as a submenu.
Make for New a cascading
submenu that contains two menu items of your choice.
Note.
1. Use JMenu, rather than JMenuItem, to create the New menu, because New is a menu, not a menu item.
2. Create a new menu item for Save
and Email for popup menu
below. Do not reuse the ones created for the menu bar as it will not
work.
2. Popup menu
Create a popup menu that contains two menu items: Save and Email. Make this popup menu
available on the toolbar, the major panel, and the course panel.
That is, when you right-click the mouse in these areas, the popup menu
should appear. This is the standard way in which a popup menu is
invoked.
You may want to study this
tutorial section first.
Note.
The tutorial shows that in order to pop up a menu on a widget, a
MouseListener needs to be registered on the widget. The mouse listener
allows us to define responses to different mouse behaviors. In our
case, we want to pop up the menu. Therefore, we need to be able to
access the popup menu inside the mouse listener.
There can be two ways to achieve this.
(1) Define the mouse listener as an anonymous class. In this way, the
popup menu can be accessed directly inside the anonymous class.
(2) Define a normal class, as the example in the tutorial does. Now we
need to pass the popup menu to the PopupListener class, which can be
done by adding to PopupListener a constructor that takes a JPopupMenu
as parameter:
class PopupListener extends
MouseAdapter {
private JPopupMenu popup;
public PopupListener(JPopupMenu popup){
this.popup
= popup;
}
// the remainder can be copied from the tutorial.
}
We can then use PopupListener to create and register a MouseListener to
any widget W on which we want to be able to popup a menu:
MouseListener popupListener = new
PopupListener(popup);
W.addMouseListener(popupListener);
3. Tool Bar
Add New, Open, Save, and Email to toolbar. Each of them must
use the icons shown below. They should also exhibit the rollover
behavior.

4. Tooltips
Add tooltips to all toolbar buttons and course checkboxes. The tooltip
for a toolbar button should explain what the button does, and the
tooltip for a course checkbook should give the full title of the
particular course.
5. ActionListener for the Email
toolbar button
When the Email button is
pressed, the name of the selected major and the list of selected
courses should be printed on console. A sample output could be
Major: Software Engineering
Selected Courses: EE408, EE363, EE368
This step is a prerequisite to actually emailing the major/course
enrollment form, which we will not attempt to implement at this time.
Make sure that the Email menu item also supports this behavior.
Note that an anonymous class may access all variables visible in its
enclosing context, but these variables must be constant, which can be
declared by adding a final
keyword before their declarations.
Demonstrate to me once you are done with these exercises so
that I can
grade.
Have a good weekend.
Bonus Task (1%+1%)
(1) As shown in the screenshot below, add a personal identity
panel to the application, which makes use of 3 new widgets, JComboBox,
JLabel, and JTextField. The ComboBox contains three items for ways in
which how a person can be addressed - "", "Ms.", and "Mr." The default
setting for the ComboBox should be "". Modify the ActionListener to
output the names of the person in addition.
Note. Default values for controls are a relevant usability
consideration. Bloopers 10 and 11 are about
properly setting up
defaults for controls.

(2) The three majors, EE, CE, and SE, all have a different list of
courses. Try to display different courses in the course panel when the
major is changed to a different one.