customitemdemo.java
来自「Java ME手机应用开发大全一书的配套光盘上的源码」· Java 代码 · 共 64 行
JAVA
64 行
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CustomItemDemo extends MIDlet
implements CommandListener
{
private TextField text;
private SimpleItem customitem;
private Command exit;
public void startApp() {
text= new TextField("姓名", "", 30, TextField.ANY);
Form form = new Form("SimpleItemMIDlet");
customitem=new SimpleItem("自定义控件");
form.append(customitem);
form.append(text);
exit = new Command("退出", Command.EXIT, 0);
form.addCommand(exit);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c==exit)
{
destroyApp(false);
notifyDestroyed();
}
}
class SimpleItem extends CustomItem {
public SimpleItem(String title) { super(title); }
// 实现CustomItem的抽象方法
public int getMinContentWidth() { return 100; }
public int getMinContentHeight() { return 60; }
public int getPrefContentWidth(int width) {
return getMinContentWidth();
}
public int getPrefContentHeight(int height) {
return getMinContentHeight();
}
public void paint(Graphics g, int w, int h) {
g.drawRect(0, 0, w - 1, h - 1);
g.setColor(0x000000ff);
g.drawString(text.getString(),0,0,0);
}
public void commandAction(Command c, Item i)
{
repaint();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?