手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>Java技术>列表

猜数字游戏,我的第一个J2ME程序,很多问题,有待于解决

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

import Javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

/**
*
* @author aoenzh
* @version
*/
public class Test extends MIDlet implements CommandListener{

private Command cmdOK;
private Command cmdEXIT;
private TextField txtInput;
private Form myForm;
private int rndNum;
//private int inputNum;
Display display;
public Test(){

}

public void startApp() {
Random tmpRand=new Random();
rndNum=tmpRand.nextInt(100);
txtInput=new TextField("请输入0-50之间的数字","",25,TextField.NUMERIC);
cmdOK=new Command("确认",Command.SCREEN,1);
cmdEXIT=new Command("退出",Command.EXIT,1);
myForm=new Form("猜数字");
myForm.append(txtInput);
myForm.addCommand(cmdOK);
myForm.addCommand(cmdEXIT);
myForm.setCommandListener(this);
display =Display.getDisplay(this);
display.setCurrent(myForm);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command command, Displayable displayable) {
if(command==cmdEXIT){
destroyApp(true);
notifyDestroyed();
}
if(command==cmdOK){
Alert alert = new Alert("猜数字","",null,AlertType.INFO);
String input = txtInput.getString();
int temp;
if(input.length()>0){
temp = Integer.parseInt(input);
} else{
temp=0;
}
alert.setTimeout(3000);
if(temp > rndNum){
alert.setString("大了,笨蛋!");
Display.getDisplay(this).setCurrent(alert);
}
if(temp == rndNum){
alert.setString("佩服佩服!");
Display.getDisplay(this).setCurrent(alert);
//this.startApp();
}
if(temp < rndNum){
alert.setString("小了,笨蛋!");
Display.getDisplay(this).setCurrent(alert);
}
txtInput.setString("");
}
}

}

上一篇: 通过文本文档实现信息的批量导入
下一篇: jsp tomcat mysql&sevlet&javabean配置全过程

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!