By: Lakshmi Printer Friendly Format
The user can set the value of an interactive gauge. Simply scroll the display to highlight the first gauge. It takes on a solid rendering when highlighted and is grayed out when not highlighted. Using the left and right arrow buttons that appear at the bottom of the screen, you can modify the gauge's value. Like the vertical arrows you've seen already, these horizontal arrows are created and managed by the implementation.
Notice that you have to click the arrow keys several times
before you see an increase or decrease in the number of bars that are filled in. The reason is the
limited screen resolution that the gauge is able to display. If the overall range of values that the gauge
represents is too great, the gauge implementation must map several values to each vertical bar that
appears on the gauge's display. The bottom arrow on the screen indicates that you can scroll
down the display further.
gauge. Scrolling the display to the bottom will display the whole of the non-interactive gauge. After you've scrolled down, notice that now there are no left and right arrows, because the value of non-interactive gauges cannot be changed.
It's important to distinguish between the ability to interact with a gauge and the ability to modify its value. Both types of gauges can be modified programmatically.
The abbreviated source code belo shows how to set the maximum and initial values of a Gauge in the constructor.
The four parameters required to specify a gauge are its mode, human readable title, initial value, and maximum value.
This class demonstrates the use of the Gauge MIDP UI
public class GaugeDemo extends Form
private String gauge1Label = new String("Interactive gauge");
private Gauge interactiveGauge =
new Gauge("Interactive", true, 50, 15);
private String gauge2Label = new String("Non-interactive");
private Gauge staticGauge = new Gauge("Static", false, 50, 25);
instance = this;
Unlike the demo, a real application would presumably also change the gauge value during its lifetime, using the following methods in the Gauge class:
public void setValue(int value)
public int getValue()
Most Viewed Articles (in J2ME )
Latest Articles (in J2ME)
Comment on this tutorial
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews