Java by API/javax.microedition.lcdui/Alert — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:49, 31 мая 2010
Содержание
Alert.FOREVER
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public class J2MEListImplicit extends MIDlet implements CommandListener {
private Display display;
private List list;
private Command exit;
Alert alert;
public J2MEListImplicit() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
list = new List("Menu:", List.IMPLICIT);
list.append("New", null);
list.append("Open", null);
list.addCommand(exit);
list.setCommandListener(this);
}
public void startApp() {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == List.SELECT_COMMAND) {
String selection = list.getString(list.getSelectedIndex());
alert = new Alert("Option Selected", selection, null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
display.setCurrent(alert);
} else if (command == exit) {
destroyApp(false);
notifyDestroyed();
}
}
}
Alert: setTimeout(int value)
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public class J2MEListImplicit extends MIDlet implements CommandListener {
private Display display;
private List list;
private Command exit;
Alert alert;
public J2MEListImplicit() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
list = new List("Menu:", List.IMPLICIT);
list.append("New", null);
list.append("Open", null);
list.addCommand(exit);
list.setCommandListener(this);
}
public void startApp() {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == List.SELECT_COMMAND) {
String selection = list.getString(list.getSelectedIndex());
alert = new Alert("Option Selected", selection, null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
display.setCurrent(alert);
} else if (command == exit) {
destroyApp(false);
notifyDestroyed();
}
}
}
Alert: setType(AlertType type)
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public class J2MEListImplicit extends MIDlet implements CommandListener {
private Display display;
private List list;
private Command exit;
Alert alert;
public J2MEListImplicit() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
list = new List("Menu:", List.IMPLICIT);
list.append("New", null);
list.append("Open", null);
list.addCommand(exit);
list.setCommandListener(this);
}
public void startApp() {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == List.SELECT_COMMAND) {
String selection = list.getString(list.getSelectedIndex());
alert = new Alert("Option Selected", selection, null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
display.setCurrent(alert);
} else if (command == exit) {
destroyApp(false);
notifyDestroyed();
}
}
}
new Alert(String title, String alertText, Image alertImage, AlertType alertType)
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
public class Main extends MIDlet implements CommandListener {
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command setLabelCommand = new Command("Label", Command.SCREEN, 1);
private Command setTextCommand = new Command("Text", Command.SCREEN, 1);
private Command getLabelTextCommand = new Command("Get", Command.SCREEN, 1);
private StringItem stringItem1 = new StringItem("Label1", "Content1");
private StringItem stringItem2 = new StringItem(null, "Content2");
private Display display = Display.getDisplay(this);
public Main() {
}
public void startApp() {
Form aForm = new Form("StringItem");
aForm.append(stringItem1);
aForm.append(stringItem2);
aForm.addCommand(exitCommand);
aForm.addCommand(setLabelCommand);
aForm.addCommand(setTextCommand);
aForm.addCommand(getLabelTextCommand);
aForm.setCommandListener(this);
display.setCurrent(aForm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (c == setLabelCommand)
stringItem1.setLabel("new label");
if (c == setTextCommand)
stringItem2.setText("new text");
if (c == getLabelTextCommand) {
Alert alert = new Alert("Info", stringItem1.getLabel() + ":" + stringItem1.getText(), null,
AlertType.INFO);
alert.setTimeout(5000);
display.setCurrent(alert);
}
}
}