📄 customitemdemo.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -