Java Reference
In-Depth Information
Progress Bars
A progress bar is a component that visually displays a value within an inter-
val, and typically represents the progress of a certain task being performed. If
you have ever downloaded a file off the Internet, you have seen a progress bar
in action. The AWT does not have a class for progress bars, so if you want to
use a progress bar in AWT you are going to have write one from scratch.
Swing contains the javax.swing.JProgressBar class to represent a progress bar,
and has five constructors that take in a variation of the following parameters:
int min. The lower bound of the progress bar, which is 0 by default.
int max. The upper bound of the progress bar, which is 100 by default.
int orient. Can be one of two values: JProgressBar.VERTICAL or JPro-
gressBar.HORIZONTAL, and determines which way the progress bar
appears in its container. The default orientation is a horizontal progress
fire.
BoundedRangeModel model. Represents a data model that consists of a
range with a minimum, maximum, extent, and current value.
A JProgressBar generates a ChangeEvent when the current value changes,
and a listener is added using the addChangeListener() method. The current
value is accessed using the setValue() and getValue() methods, and there are
similar methods for accessing the orientation and minimum and maximum
values.
The MenuDemo program in the next section demonstrates using the
JProgressBar class to create and manage a progress bar.
Menus
A menu is a common feature of Frame and JFrame windows. There are three
components to a menu:
A menu bar, which is attached to the window. The menu bar is typically
shown at the top of a window.
■■
A menu, which is attached to the menu bar or another menu. The
menus have a label, and clicking on the label causes the menu to drop
down and display its menu items.
■■
A menu item, which is attached to a menu. Selecting a menu item gen-
erates an ActionEvent.
■■
Search WWH ::




Custom Search