国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

猜數字游戲,我的第一個J2ME程序,很多問題,有待于解決

2019-11-17 06:19:25
字體:
來源:轉載
供稿:網友

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



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 曲水县| 宣武区| 永善县| 察隅县| 凤城市| 姜堰市| 洛南县| 金湖县| 禄劝| 宜川县| 高唐县| 楚雄市| 凉山| 扎兰屯市| 温州市| 黄山市| 清苑县| 宁城县| 禄劝| 连城县| 凉城县| 藁城市| 沐川县| 江达县| 溧水县| 芒康县| 巨鹿县| 扶余县| 遂平县| 大厂| 松原市| 平安县| 榆中县| 荆门市| 绍兴市| 永宁县| 镇巴县| 金昌市| 和田县| 苗栗市| 太原市|