java速度入门九_j2me基本控件

本文介绍了如何使用Java在S60平台上开发MIDlet应用,通过创建一个包含文本框的Form来展示基本的UI元素。文章详细说明了MIDlet生命周期方法和如何在应用中添加交互元素。

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

}

}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值