By: Lakshmi Emailed: 1766 times Printed: 2515 times
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()
View Tutorial By: Marimuthu at 2009-07-20 00:56:27
View Tutorial By: SIVAKUMAR at 2011-11-22 11:14:05
Most Viewed Articles (in J2ME )
Most Emailed Articles (in J2ME)