Gauge sample program in J2ME
By: Lakshmi
The J2ME example shown below places four items on a Form: two gauges and a String label for each one. The labels identify the two different types of gauges defined by the Gauge class: interactive and non-interactive. The implementation renders the two types of gauges differently so the user can distinguish their type.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.
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
/**
This class demonstrates the use of the Gauge MIDP UI
class.
@see javax.microedition.lcdui.Gauge
*/
public class GaugeDemo extends Form
implements CommandListener
{
...
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);
/**
Constructor.
*/
public GaugeDemo()
{
super("Gauge Demo");
append(gauge1Label);
append(interactiveGauge);
append(gauge2Label);
append(staticGauge);
addCommand(back);
setCommandListener(this);
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()
Archived Comments
1. Ur article is very intersting and very usefull me and my project.I had one doubt the picture in gaug
View Tutorial By: SIVAKUMAR at 2011-11-22 11:14:05
2. I got intersting idea about gauge,thanks...
View Tutorial By: Marimuthu at 2009-07-20 00:56:27
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Code sample to Send SMS from a J2ME application.
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Using HTTP vs UDP vs Socket in J2ME
RMSCookieConnector - Using Cookies in J2ME
Client Server in J2ME (Socket Programming sample)
Datagrams in J2ME (UDP Programming sample)
POST UTF-8 encoded data to the server in J2ME
Using alerts and tickers in J2ME
Using List to create a Menu and Menu items in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
Timer and TimerTask example in J2ME