Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home J2me Creating Volume Bar Using Gauge Class

Related Tutorials


 
 

Share on Google+Share on Google+

Creating Volume Bar Using Gauge Class

Advertisement
This example is all about creating a volume bar using Gauge class. We are creating the object of Gauge class that contains the following parameters label, interactive, maxValue and initialValue and it has been set with the form.

Creating Volume Bar Using Gauge Class

     

This example is all about creating a volume bar using Gauge class. We are creating the object of Gauge class that contains the following parameters label, interactive, maxValue and initialValue and it has been set with the form.  We can also set the new volume label, if the interactive  status is true. But if the status is set as  false then we can not change the value of bar label. The following code is used to create the gauge and to display the current status:

gauge = new Gauge("Volume", true, 52);
sitem = new StringItem(null, "[value]");
itemStateChanged(gauge);

The Application is as follows:

Source Code of VolumeExample.java

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class VolumeExample extends MIDlet implements ItemStateListener, CommandListener{
  private Form form;
  private Display display;
  private Command exit;
  private Gauge gauge;
  private StringItem sitem;

  public VolumeExample(){
  gauge = new Gauge("Volume", true, 5, 2);
  sitem = new StringItem(null, "[value]");
  itemStateChanged(gauge);
  }

  public void startApp(){
  Form form = new Form("GaugeExample");
  exit = new Command("Exit", Command.EXIT, 0);
  display = Display.getDisplay(this);
  form.append(gauge);
  form.append(sitem);
  form.addCommand(exit);
  form.setCommandListener(this);
  form.setItemStateListener(this);
  display.setCurrent(form);
  }

  public void itemStateChanged(Item item){
  if (item == gauge){
  sitem.setText("Volume Label = " + gauge.getValue());
  }
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){
  notifyDestroyed();
  }

  public void commandAction(Command c, Displayable s){
  String label = c.getLabel();
  if (label.equals("EXIT")){
  destroyApp(false);
  }  
  }
}

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Related Tutorials

Discuss: Creating Volume Bar Using Gauge Class  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
periyasamy
April 8, 2011
j2me

how to create persetage of bar graph using gauge in j2me
DMCA.com