⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countdown.java

📁 《精通JAVA手机游戏与应用程序设计》随书光盘
💻 JAVA
字号:
package countDown;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class CountDown extends MIDlet implements CommandListener {

	private Command exitCommand, beginCommand, setupCommand, backCommand;

	private TextField hourTF, minuteTF, secondTF;

	private Form mainForm;

	private CountDownCanvas cdcanvas;

	private int hour = 0, minute = 0, second = 0;

	public CountDown() {

		exitCommand = new Command("退出", Command.EXIT, 1);
		beginCommand = new Command("开始", Command.SCREEN, 1);

		//创建主屏幕
		mainForm = new Form("倒计时");
		hourTF = new TextField("输入小于12的小时数", "", 2, TextField.NUMERIC);
		minuteTF = new TextField("输入小于60的分钟数", "", 2, TextField.NUMERIC);
		secondTF = new TextField("输入小于60的秒数", "", 2, TextField.NUMERIC);

		mainForm.append(hourTF);
		mainForm.append(minuteTF);
		mainForm.append(secondTF);

		mainForm.addCommand(exitCommand);
		mainForm.addCommand(beginCommand);
		mainForm.setCommandListener(this);

		Display.getDisplay(this).setCurrent(mainForm);

	}

	protected void startApp() {
	}

	protected void pauseApp() {
	}

	protected void destroyApp(boolean arg0) {
	}

	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {
			destroyApp(false);
			notifyDestroyed();
		}
		if (c == beginCommand) {
			//创建倒计时屏幕
			try {
				hour = Integer.parseInt(hourTF.getString());
				System.out.println(hour);
				minute = Integer.parseInt(minuteTF.getString());
				second = Integer.parseInt(secondTF.getString());
			} catch (Exception e) {
				Alert a = new Alert("提醒", "还没有输入数字", null, AlertType.ERROR);
				a.setTimeout(Alert.FOREVER);
				a.setCommandListener(this);
				Display.getDisplay(this).setCurrent(a);
			}

			backCommand = new Command("设置", Command.SCREEN, 1);

			cdcanvas = new CountDownCanvas(hour, minute, second);
			cdcanvas.addCommand(exitCommand);
			cdcanvas.addCommand(backCommand);
			cdcanvas.setCommandListener(this);
			Display.getDisplay(this).setCurrent(cdcanvas);
		}
		if (c == backCommand) {
			Display.getDisplay(this).setCurrent(mainForm);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -