📄 mainmidlet.java
字号:
package com.supinfo.cargame;
import java.util.Timer;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.supinfo.cargame.GameCanvas;
import com.supinfo.cargame.GameTask;
public class MainMidlet extends MIDlet implements CommandListener{
private Display display;
ChoiceGroup group;
Gauge gauge;
private Command cmdExt;
private Command cmdStr;
public MainMidlet() {
display = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
//form
Form form = new Form("start the game");
//welcome message
StringItem welcome = new StringItem("","Welcome !!!!");
//select the speed
gauge = new Gauge("Speed ",true,5,1);
//the color of the car
String[] dif ={"Red","Greenl","Blue","Yellow","Black"};
group = new ChoiceGroup("Difficulty",List.EXCLUSIVE,dif,null);
form.append(welcome);
form.append(gauge);
form.append(group);
//command
cmdStr = new Command("start",Command.OK,1);
cmdExt = new Command("exit",Command.EXIT,2);
new Command("Back",Command.BACK,3);
form.addCommand(cmdStr);
form.addCommand(cmdExt);
form.setCommandListener(this);
display.setCurrent(form);
}
public void commandAction(Command cmd, Displayable arg1) {
if ( cmd == cmdExt)
{
try {
destroyApp(true);
notifyDestroyed();
} catch ( MIDletStateChangeException e) {
// TODO: handle exception
e.printStackTrace();
}
}
if (cmd == cmdStr) {
int spe= gauge.getValue();
int col= group.getSelectedIndex();
GameCanvas canvas = new GameCanvas(col);
GameTask gameTask =new GameTask(canvas);
Timer timer = new Timer();
if (spe==1) {
timer.schedule(gameTask, 1000,200);
}
if (spe==2) {
timer.schedule(gameTask, 1000,150);
}
if (spe==3) {
timer.schedule(gameTask, 1000,100);
}
if (spe==4) {
timer.schedule(gameTask, 1000,50);
}
if (spe==5) {
timer.schedule(gameTask, 1000,20);
}
Display.getDisplay(this).setCurrent(canvas);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -