Wednesday, December 12, 2012
Membangkitkan suara untuk objek Alert pada JAVA (J2ME)
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class SuaraAlert extends MIDlet
implements CommandListener {
private Display display;
private List list;
private final Command cmdKeluar =
new Command("Keluar", Command.EXIT, 1);
private final Command cmdOK =
new Command("OK", Command.SCREEN, 1);
public SuaraAlert() {
display = Display.getDisplay(this);
list = new List("Tipe Alert", Choice.EXCLUSIVE);
list.append("Info", null);
list.append("Warning", null);
list.append("Error", null);
list.append("Confirmation", null);
list.append("Alarm", null);
list.addCommand(cmdOK);
list.addCommand(cmdKeluar);
list.setCommandListener(this);
}
public void startApp() {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
notifyDestroyed();
} else if (c == cmdOK) {
switch (list.getSelectedIndex()) {
case 0: {
displayAlert("Tipe INFO", AlertType.INFO);
break;
}
case 1: {
displayAlert("Tipe WARNING", AlertType.WARNING);
break;
}
case 2: {
displayAlert("Tipe ERROR", AlertType.ERROR); break;
}
case 3: {
displayAlert("Tipe CONFIRMATION",
AlertType.CONFIRMATION);
break;
}
case 4: {
displayAlert("Tipe ALARM", AlertType.ALARM);
break;
}
}
}
}
public void displayAlert(String text, AlertType type) {
Alert alert = new Alert("Suara dalam Alert", text,
null, type);
display.setCurrent(alert);
type.playSound(display);
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment