Java Reference
In-Depth Information
Gauge
Gauge represents an integer value. It's up to the implementation of the Gauge class to decide
how to display it. In Sun's MIDP implementation, Gauge appears as shown in Figure 6-10.
Figure 6-10. A gauge
The value of a Gauge instance can be retrieved and modified with the getValue() and
setValue() methods. This value runs from 0 to a variable maximum value. The maximum for
the gauge can be retrieved and modified with the getMaxValue() and setMaxValue() methods.
The visual appearance of the Gauge is an approximation of the gauge's value. The gauge
shown in Figure 6-10 could, for example, have a value of 7 and a maximum of 10, or perhaps a
value of 42 and a maximum of 61.
In an interactive gauge, the user can modify the value. Again, it's up to the implementation
to decide exactly how this works. In Sun's reference implementation, the left and right naviga-
tion buttons can be used to modify a gauge's value.
Gauge 's constructor is straightforward:
public Gauge(String label, boolean interactive,
int maxValue, int initialValue)
For example, the following code creates an interactive Gauge with a maximum value of 24
and an initial value of 2:
Gauge g = new Gauge( " Power " , true, 24, 2);
There are three varieties of noninteractive gauges that can be useful as progress indicators.
You can use a regular noninteractive gauge with a known maximum value to show the progress
of a download or a calculation. For example, if you were going to run through a loop 20 times,
you could create a gauge with a maximum of 20 and update its value each time through the loop.
There are two kinds of noninteractive gauges with no maximum value. In this case, you
use the special value INDEFINITE for the maximum. Such gauges can be either incremental or
continuous . An incremental gauge shows an operation with measurable steps; your application
will update the gauge every time it does something significant. For example, if you were down-
loading a file, but you didn't know how big it was, you could use an incremental gauge and
 
Search WWH ::




Custom Search