popupbuttons.java
来自「Java ME手机应用开发大全一书的配套光盘上的源码」· Java 代码 · 共 65 行
JAVA
65 行
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class PopupButtons extends MIDlet implements CommandListener
{
private Display display;
private Form form;
private Command exit;
private Command process;
private ChoiceGroup item;
private int currentIndex;
private int genderIndex;
private Image img1,img2,img3;
public PopupButtons()
{
try
{
img1=Image.createImage("/1.png");
img2=Image.createImage("/2.png");
img3=Image.createImage("/3.png");
}
catch (Exception e)
{
}
display = Display.getDisplay(this);
item = new ChoiceGroup("Popup", Choice.POPUP);
item.append("Option1", img1);
item.append("Option2", img2);
currentIndex = item.append("Option3", img3);
item.setSelectedIndex(currentIndex, true);
exit = new Command("退出", Command.EXIT, 1);
process = new Command("提交", Command.SCREEN,2);
form = new Form("");
genderIndex = form.append(item);
form.addCommand(exit);
form.addCommand(process);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command command, Displayable displayable)
{
if (command == exit)
{
destroyApp(false);
notifyDestroyed();
}
else if (command == process)
{
currentIndex = item.getSelectedIndex();
StringItem message = new StringItem("选择的选项是", item.getString(currentIndex));
form.append(message);
form.delete(genderIndex);
form.removeCommand(process);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?