📄 formdemo.java
字号:
//formDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class formDemo extends MIDlet implements CommandListener, ItemStateListener
{
private Command exitCommand;
private Form form;
public formDemo()
{
exitCommand =new Command("Exit",Command.EXIT,1);
form = new Form("summary form");
form.addCommand(exitCommand);
//设置命令监听对象
form.setCommandListener(this);
form.append("Fill the Form to Register a new account\n\rAll the blank will be filled !");
form.append(new TextField("Name","",10,TextField.ANY));
form.append(new TextField("Birth(YYMMDD)","",6,TextField.NUMERIC));
form.append(new TextField("Email","",40,TextField.EMAILADDR));
form.append(new TextField("Phone","",20,TextField.PHONENUMBER));
form.append(new TextField("Fax","",20,TextField.PHONENUMBER));
form.append(new TextField("Homepage","",40,TextField.URL));
form.append(new TextField("Password","",6,TextField.PASSWORD));
form.append(new TextField("Password confirm","",6,TextField.PASSWORD));
form.append(new TextField("ur intro","",200,TextField.ANY));
//从上面的代码我们注意到我们没有保存每个被创建的TextField 对象
//当我们需要使用这些对象时我们可以利用Form.get(int itemNum) 从对象位置来得到每个对象
//设置状态监听对象
form.setItemStateListener(this);
}
protected void startApp( ) throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(form);
}
protected void pauseApp( )
{
}
protected void destroyApp( boolean p1 )
{
}
public void commandAction(Command c,Displayable d)
{
if (c ==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
public void itemStateChanged(Item item)
{
if( item instanceof TextField)
{
System.out.println("TextField : "+ ((TextField)item).getLabel() +" changed");
System.out.println("LastValue : "+ ((TextField)item).getString() );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -