📄 myclass.java
字号:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import java.util.Random;
import java.util.*;
public class MyClass extends MIDlet implements CommandListener{
private Display midletDisplay;
private Command cmdExit;
private Random rand = new Random();
public int RandomNumber = 0;
public int answer;
private Command cmdGuess;
public TextBox mainScreen;
private Ticker ticker;
public Form form;
private TextField ans;
//private Command mCommand1, mCommand2, mCommand3, mCommand4, mCommand5;
//private List ImplicitList;
//private List ExclusiveList;
//private List MultipleList;
public MyClass(){
midletDisplay = Display.getDisplay(this);
cmdExit = new Command("Exit", Command.EXIT, 0);
cmdGuess = new Command("Guess", Command.SCREEN, 1);
//mainScreen = new TextBox("Answer", "", 8, TextField.NUMERIC);
ticker = new Ticker ("Welcome! I have a magic number (0-9). Guess what is it!!");
ans = new TextField("Answer", "", 1, TextField.NUMERIC);
//ticker = new Ticker("")
form = new Form("Guess Number");
try{
Image im = Image.createImage("/game.png");
form.append(new ImageItem(null, im, ImageItem.LAYOUT_CENTER, null));
}catch (java.io.IOException e){
System.out.println("Unable to handle the pic");
}
form.setTicker(ticker);
form.append(ans);
form.addCommand(cmdExit);
form.addCommand(cmdGuess);
form.setCommandListener(this);
//String StringList[] = {"List 0","List 1","List 2","List 3","List 4"};
/*ImplicitList = new List("Document Option:", List.IMPLICIT, StringList, null);
ImplicitList.addCommand(cmdExit);
ImplicitList.setCommandListener(this);*/
/*mCommand1 = new Command("Button1", Command.SCREEN, 0);
mCommand2 = new Command("Button2", Command.SCREEN, 1);
mCommand3 = new Command("Button3", Command.SCREEN, 2);
mCommand4 = new Command("Button4", Command.SCREEN, 3);
mCommand5 = new Command("Button5", Command.SCREEN, 4);*/
/*ExclusiveList = new List("Document Option:", List.EXCLUSIVE, StringList, null);
ExclusiveList.addCommand(cmdExit);
ExclusiveList.setCommandListener(this);*/
/*MultipleList = new List("Document Option:", List.MULTIPLE, StringList, null);
MultipleList.addCommand(cmdExit);
MultipleList.setCommandListener(this);*/
/*
try{
Image ImageList[] = { Image.createImage("/list0.png"),
Image.createImage("/list1.png"),
Image.createImage("/list2.png"),
Image.createImage("/list3.png"),
Image.createImage("/list4.png")};
ImplicitList = new List("Document Option:", List.IMPLICIT, StringList, ImageList);
ImplicitList.addCommand(cmdExit);
ImplicitList.setCommandListener(this);
} catch (java.io.IOException e){
System.err.println("Unable to locate or read ");
}*/
}
public void startApp(){
//RandomNumber = Math.abs(rand.nextInt())%9;
RandomNumber = 8;
//midletDisplay.setCurrent(ImplicitList);
midletDisplay.setCurrent(form);
//midletDisplay.setCurrent(ExclusiveList);
//midletDisplay.setCurrent(MultipleList);
/*TextBox mainScreen = new TextBox("Title", "Content", 50, TextField.ANY);
mainScreen.addCommand(cmdExit);
mainScreen.addCommand(mCommand1);
mainScreen.addCommand(mCommand2);
mainScreen.addCommand(mCommand3);
mainScreen.addCommand(mCommand4);
mainScreen.addCommand(mCommand5);
mainScreen.setCommandListener(this);
midletDisplay.setCurrent(mainScreen);*/
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command c, Displayable s){
/*if(c==cmdExit){
destroyApp(true);
notifyDestroyed();
}else if (c == mCommand1){
System.out.println("Button 1 ");
}else if (c == mCommand2){
System.out.println("Button 2 ");
}else if (c == mCommand3){
System.out.println("Button 3 ");
}else if (c == mCommand4){
System.out.println("Button 4 ");
}else if (c == mCommand5){
System.out.println("Button 5 ");
}*/
/*
if(c == List.SELECT_COMMAND){
switch (ImplicitList.getSelectedIndex()){
case 0:
System.out.println("List 0 Selected");
break;
case 1:
System.out.println("List 1 Selected");
break;
case 2:
System.out.println("List 2 Selected");
break;
case 3:
System.out.println("List 3 Selected");
break;
case 4:
System.out.println("List 4 Selected");
break;
}
}else if (c == cmdExit){
destroyApp(true);
notifyDestroyed();
}*/
/*
if(c==cmdExit){
destroyApp(true);
notifyDestroyed();
}*/
if(c==cmdGuess){
try{
Image im =Image.createImage("/list1.png");
Alert al = new Alert("","",im,AlertType.CONFIRMATION);
answer = Integer.parseInt(ans.getString());
if (answer ==8){
im = Image.createImage("/correct.png");
al = new Alert("Congratulation", "You're correct!", im, AlertType.CONFIRMATION);
}else{
im = Image.createImage("/error.png");
al = new Alert("Sorry", "You're Wrong!", im, AlertType.CONFIRMATION);
}
midletDisplay.setCurrent(al);
} catch (java.io.IOException e){
System.err.println("Unable to locate or read the PNG file");
}
}else if (c==cmdExit){
destroyApp(true);
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -