Practical Exercise 11 using BlueJ

Note that this exercise is based on Barnes and Koelling, Objects First, Chapter 11.

Before starting these exercises copy (right click then save as) to your home directory (e.g.Z:\My Documents) and unzip it.


  1. 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 frame?
  2. Replace the label (JLabel) in the example with a button (JButton)
  3. What happens when you add two buttons to the content frame? Experiment with resizing the frame.

  4. 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.
  5. 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");
  6. Add another menu called 'Help' that contains a menu item called  'About ImageViewer'.
  7. What happens when you use the Help button?
  8. Write a method which prints "Help Button Pushed" to output.
  9. The "Centralised Receipt of Events" method involves three steps:
  10. 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.
  • Add code to handle the other buttons in the file menu.