[an error occurred while processing this directive]

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, 52);
    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

                         

[an error occurred while processing this directive]