Practical Exercise 11 using BlueJ
Note that this exercise is based on
Barnes and Koelling, Objects First,
Before starting these exercises copy (right click then save as)
projects.zip to your home directory (e.g.Z:\My Documents) and unzip it.
Add code to handle the other buttons in the file menu.
- Open imageviewer0-1. Create an instance of class ImageViewer. Resize the
resulting frame. What do you observe about the placement of the text in the
- Replace the label (JLabel) in the example with a button (JButton)
What happens when you add two buttons to the content frame? Experiment with
resizing the frame.
- The following code adds a menu bar. Find out what is in the menu bar
by arranging for this code to be used. To do this you need to include the method and
call it at the appropriate place.
private void makeMenuBar(JFrame frame)
JMenuBar menubar = new JMenuBar();
// create the File menu
JMenu fileMenu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open");
JMenuItem quitItem = new JMenuItem("Quit");
- Add another menu called 'Help' that contains a menu item called 'About
- What happens when you use the Help button?
- Write a method which prints "Help Button Pushed" to output.
- The "Centralised Receipt of Events" method involves three steps:
- Implement the "Centralised Receipt of Events" menu-handling code
so that when the menu button "Help" is pressed, the method you just wrote is invoked.