Java Reference
In-Depth Information
Exercise 11.53
What is a
slider
? Find a description and summarize. Give a short example
in Java code about creating and using a slider.
Exercise 11.54
What is a
tabbed pane
? Find a description and summarize. Give examples
of what a tabbed pane might be used for.
Exercise 11.55
What is a
spinner
? Find a description and summarize.
Exercise 11.56
Find the demo application
ProgressBarDemo
. Run it on your computer.
Describe what it does.
This is where we shall leave the discussion of the image-viewer example. It can, however, be
extended in many directions by interested readers. Using the information from the online tuto-
rial, you can add numerous interface components.
The following exercises give you some ideas, and obviously there are many more possibilities.
Exercise 11.57
Implement an
undo
function in your image viewer. This function reverses
the last operation.
Exercise 11.58
Disable all menu items that cannot be used when no image is being displayed.
Exercise 11.59
Implement a
reload
function that discards all changes to the current image
and reloads it from disk.
Exercise 11.60
The
JMenu
class is actually a subclass of
JMenuItem
. This means that
nested menus can be created by placing one
JMenu
inside another. Add an
Adjust
menu to
the menu bar. Nest within it a
Rotate
menu that allows the image to be rotated either 90 or 180
degrees, clockwise or counterclockwise. Implement this functionality. The
Adjust
menu could
also contain menu items that invoke the existing
Larger
and
Smaller
functionality, for instance.
Exercise 11.61
The application always resizes its frame in order to ensure that the full image
is always visible. Having a large frame is not always desirable. Read the documentation on the
JScrollPane
class. Instead of adding the
ImagePanel
directly to the content pane, place
the panel in a
JScrollPane
and add the scroll pane to the content pane. Display a large im-
age and experiment with resizing the window. What difference does having a scroll pane make?
Does this allow you to display images that would otherwise be too large for the screen?
Exercise 11.62
Change your application so that it can open multiple images at the same
time (but only one image is displayed at any time). Then add a pop-up menu (using class
JComboBox
) to select the image to display.
Exercise 11.63
As an alternative to using a
JComboBox
as in Exercise 11.62, use a
tabbed pane (class
JTabbedPane
) to hold multiple open images.
Search WWH ::
Custom Search