Gauge sample program in J2ME

By: Lakshmi Emailed: 1766 times Printed: 2515 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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()


J2ME Home | All J2ME Tutorials | Latest J2ME Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(2)


1. View Comment

I got intersting idea about gauge,thanks...

View Tutorial          By: Marimuthu at 2009-07-20 00:56:27
2. View Comment

Ur article is very intersting and very usefull me and my project.I had one doubt the picture in gauge is mobile phone dependent or we set our image also.

View Tutorial          By: SIVAKUMAR at 2011-11-22 11:14:05

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Lakshmi
Exporting a Certificate Authenticating Your Public Key example using keytool in Java
while and do-while example in Java
Common SQL Commands
Data Access Technologies in Java
perror() Function - example program in C
Struts-GUI and Struts Console
Variable-length Argument Lists sample program in C
#if, #elif, #ifndef, #ifdef in C (Conditional Inclusion)
Use ImageButtonBean for Image based Form Submits in Struts
break and continue loops in C
Arguments - Call by Value in C
Using command-line arguments in C++
How to handle Exceptions in C++
Gauge sample program in J2ME
What is Reflection? - getConstructors(), getFields(), and getMethods()

More Tutorials in J2ME
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
Datagrams in J2ME (UDP Programming sample)
Client Server in J2ME (Socket Programming sample)
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
POST UTF-8 encoded data to the server in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
Using List to create a Menu and Menu items in J2ME
Using alerts and tickers in J2ME
J2ME Canvas sample to show games programming in J2ME
Timer and TimerTask example in J2ME
List of GPRS Access points for all countries

More Latest News
Most Viewed Articles (in J2ME )
What is J2ME?
Sample J2ME code that shows various functionality of RMS.
java.lang.SecurityException: MIDP lifecycle does not support system exit.
How to get the CLDC and MIDP version from a J2ME program
StringItem sample program in J2ME
Gauge sample program in J2ME
Sample program to draw a rectangle in J2ME
translate() Sample program in J2ME
'double buffering' Sample program in J2ME
A sample J2ME Auto-resume program.
getPosition() the right strategy in getting GPS
J2ME Canvas sample to show games programming in J2ME
Using alerts and tickers in J2ME
Download a file over a network in J2ME midlet
How to load J2ME applications to the IDEN handsets
Most Emailed Articles (in J2ME)
How to load J2ME applications to the IDEN handsets
GUI components and menu based J2ME Applications.
Ticker sample program in J2ME
Using List to create a Menu and Menu items in J2ME
What is J2ME?
'LINK.EXE' is not recognized as an internal or ext
DateField sample program in J2ME
Sample program to draw a rectangle in J2ME
Types of configurations in J2ME
Types of Profiles in J2ME
A sample J2ME Auto-resume program.
getPosition() the right strategy in getting GPS
Client Server in J2ME (Socket Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
What is J2ME?