The code given below will give you the Volume Bar with the use of Gauge Class. So, first understand it and then use it for your further use. So, you will able to use it if you need it future. So, take a look on it carefully.
Code:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class VolumeGauge extends MIDlet implements ItemStateListener, CommandListener
{
private Form frm;
private Display dis;
private Command cmd;
private Gauge gauge;
private StringItem stritem;
public VolumeGauge()
{
gauge = new Gauge("Volume", true, 5, 2);
stritem = new StringItem(null, "[value]");
itemStateChanged(gauge);
}
public void startApp(){
Form frm = new Form("GaugeExample");
cmd = new Command("Exit", Command.EXIT, 0);
dis = Display.getDisplay(this);
frm.append(gauge);
frm.append(stritem);
frm.addCommand(cmd);
frm.setCommandListener(this);
frm.setItemStateListener(this);
dis.setCurrent(frm);
}
public void itemStateChanged(Item item)
{
if (item == gauge)
{
stritem.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);
}
}
}
Bookmarks