一个textarea。
package hi;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Hi extends MIDlet {
Display display;
public static Hi instance;
public Hi() {
super();
display = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0){
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Form form = new Form("Hello S60 JAVA");
form.append("Hello World!");
display.setCurrent(form);
Display.getDisplay(this).setCurrent(new TBoxDisp("TextBox", "test for textbox", 100, 0));
}
public void exitAapp()
{
this.notifyDestroyed();
this.destroyApp(true);
}
}
package hi;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
public class TBoxDisp extends TextBox implements CommandListener {
private Command cmdOkCommand=new Command("Ok", Command.OK, 1);
private Command cmdExitCommand=new Command("Exit", Command.EXIT, 1);
private int constraints;
final static int ANY=0;
public TBoxDisp(String title,String text,int maxsize,int constraints)
{
super(title, text, maxsize, constraints);
this.constraints=constraints;
addCommand(cmdOkCommand);
addCommand(cmdExitCommand);
setCommandListener(this);
}
public void commandAction(Command arg0, Displayable arg1) {
// TODO Auto-generated method stub
if(arg0.equals(cmdOkCommand))
{
switch(constraints)
{
case ANY:
System.out.println("Type:Any Max_Size:"+this.getMaxSize()+"CurrentSize:"+this.size());
}
}else if(arg0.equals(cmdExitCommand)){
Hi.instance.exitAapp();
}
}
}
本文介绍了如何使用Java在S60平台上开发MIDlet应用,通过创建一个包含文本框的Form来展示基本的UI元素。文章详细说明了MIDlet生命周期方法和如何在应用中添加交互元素。
129

被折叠的 条评论
为什么被折叠?



