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)
projects.zip to your home directory (e.g.Z:\My Documents) and unzip it.
imageviewer0-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?
- 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();
frame.setJMenuBar(menubar);
// create the File menu
JMenu fileMenu = new JMenu("File");
menubar.add(fileMenu);
JMenuItem openItem = new JMenuItem("Open");
fileMenu.add(openItem);
JMenuItem quitItem = new JMenuItem("Quit");
fileMenu.add(quitItem);
}
- Add another menu called 'Help' that contains a menu item called 'About
ImageViewer'.
- 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.
Add code to handle the other buttons in the file menu.