📄 clockmidlet.java
字号:
import java.util.Date;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ClockMidlet extends MIDlet implements CommandListener{
private Form form; //对话框
private DateField datefield; //用于输入出生日期
private StringItem stringitem1; //用于显示测试结果
private StringItem stringitem2; //用于显示测试结果
private StringItem stringitem3; //用于显示测试结果
private Command OKCommand; //检测按钮
private Command OKCommand2; //重置按钮
private Command ExitCommand; //退出按钮
public ClockMidlet() {
super();
//创建对话框及组件,并将组件添加到对话框
form = new Form("生物钟");
datefield = new DateField("出生日期", DateField.DATE );
stringitem1 = new StringItem("体力", "无检测结果");
stringitem2 = new StringItem("情绪", "无检测结果");
stringitem3 = new StringItem("智力", "无检测结果");
form.append(datefield);
form.append(stringitem1);
form.append(stringitem2);
form.append(stringitem3);
//创建高级按钮,并将高级按钮添加到对话框
OKCommand = new Command( "检测", Command.OK, 2);
OKCommand2 = new Command( "重置", Command.OK, 1);
ExitCommand = new Command( "退出", Command.EXIT, 0);
form.addCommand(OKCommand);
form.addCommand(ExitCommand);
form.addCommand(OKCommand2);
//设置高级按钮监听器
form.setCommandListener(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
//将对话框设置为当前屏幕的显示对象
Display.getDisplay(this).setCurrent(form);
}
public void commandAction(Command c, Displayable d) {
if(c == OKCommand){ //当检测按钮被按下后
//计算总天数
Date date = datefield.getDate();
long temp = System.currentTimeMillis() - date.getTime();
long X = temp / ( 24 * 60 * 60 * 1000 );
//计算节律
long Y1 = X % 23;
long Y2 = X % 28;
long Y3 = X % 33;
//计算节律阶段,并反馈信息
if( Y1 == 0 || Y1 == 1 || Y1 == 11 || Y1 == 12 )
stringitem1.setText("处于临界期,易患疾病");
else if( Y1 < 12 )
stringitem1.setText("处于高潮期,体力充沛精力旺");
else
stringitem1.setText("处于低潮期,体力不足易疲劳");
if( Y2 == 0 || Y2 == 1 || Y2 == 23 || Y2 == 24 || Y2 == 25 )
stringitem2.setText("处于临界期,容易冲动");
else if( Y2 < 24 )
stringitem2.setText("处于高潮期,情绪高精神爽");
else
stringitem2.setText("处于低潮期,情绪低心情烦");
if( Y3 == 0 || Y3 == 1 || Y3 == 16 || Y3 == 17 )
stringitem3.setText("处于临界期,易出差错");
else if( Y3 < 17 )
stringitem3.setText("处于高潮期,思维敏捷反应快");
else
stringitem3.setText("处于低潮期,反应迟钝记忆差");
}
if(c == ExitCommand){ //当退出按钮按下后,退出程序
notifyDestroyed();
}
if(c == OKCommand2){ //当重置按钮按下后,重置显示信息
stringitem1.setText("无检测结果");
stringitem2.setText("无检测结果");
stringitem3.setText("无检测结果");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -