一个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();
}
}
}