Tuesday, August 5, 2008

Play Tone while showing Alert in J2ME application [Source Code]

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

public class AlertSound extends MIDlet implements CommandListener {
private Display display;
private Command cmdExit;
private Command info;
private Command confirmation;
private Command warning;
private Command alarm;
private Command error;
private Form form;

public void startApp() {
display = Display.getDisplay(this);
form = new Form("Alert Tone");
cmdExit = new Command("Exit", Command.EXIT, 0);
form.addCommand(cmdExit);
info = new Command("Information", Command.SCREEN, 0);
form.addCommand(info);
confirmation = new Command("Confirmation", Command.SCREEN, 0);
form.addCommand(confirmation);
warning = new Command("Warning", Command.SCREEN, 0);
form.addCommand(warning);
alarm = new Command("Alarm", Command.SCREEN, 0);
form.addCommand(alarm);
error = new Command("Error", Command.SCREEN, 0);
form.addCommand(error);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void pauseApp() {
}

protected void destroyApp(boolean arg0) {
}

public void commandAction(Command c, Displayable s) {
if (c == info)
AlertType.INFO.playSound(display);
else if (c == confirmation)
AlertType.CONFIRMATION.playSound(display);
else if (c == warning)
AlertType.WARNING.playSound(display);
else if (c == alarm)
AlertType.ALARM.playSound(display);
else if (c == error)
AlertType.ERROR.playSound(display);
else if (c == cmdExit) {
destroyApp(true);
notifyDestroyed();
}
}
}

No comments:

search engine

Custom Search