📄 mainmenucanvas.java
字号:
/**
*
* 主选择菜单界面
*
*
*/
package card;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Image;
import card.stringtable.ImageStringTable;
import java.io.IOException;
public class MainMenuCanvas extends Canvas{
private Image imgMainMenu = null;
private Display display = null;
private Image imgMenuChoice = null;
protected final int MENU_NEWGAME = 0;
protected final int MENU_HIGHSCORE = 1;
protected final int MENU_SETTINGS = 2;
protected final int MENU_HELP = 3;
protected final int MENU_ABOUT = 4;
protected final int MENU_EXITGAME = 5;
protected int iMenuX, iMenuY, iMenuWidth, iMenuHeight;
protected int iGameStatus;
protected int iMenuChoice;
FigureChoiceCanvas cvsFigureChoice = null;
HighScoreForm frmHighScore = null;
SettingsForm frmSettings = null;
HelpList frmHelp = null;
AboutForm frmAbout = null;
protected int iSoundSeleted;
public MainMenuCanvas(Display display) {
this.setFullScreenMode(true);
this.display = display;
iMenuX = 35;
iMenuY = 82;
iMenuWidth = 120;
iMenuHeight = 19;
iMenuChoice = MENU_NEWGAME;
}
public void init() {
try {
imgMainMenu = Image.createImage(ImageStringTable.getImgMainMenuString()) ;
imgMenuChoice = Image.createImage(ImageStringTable.getImgMenuSelectedString());
} catch (IOException e) { //图片载入错误处理
ErrorHandling ehIOException = new ErrorHandling(display, ErrorHandling.IMGNOTFOUND);
}
}
protected synchronized void keyPressed(int keyCode) {
int iKey = getGameAction(keyCode);
switch (iKey) {
case Canvas.UP:
if (iMenuChoice > MENU_NEWGAME) {
iMenuChoice--;
}
break;
case Canvas.DOWN:
if (iMenuChoice < MENU_EXITGAME) {
iMenuChoice++;
}
break;
case Canvas.FIRE:
if (iMenuChoice == MENU_NEWGAME) { //选择进入新游戏
if (cvsFigureChoice == null) {
cvsFigureChoice = new FigureChoiceCanvas(display);
}
display.setCurrent(cvsFigureChoice);
cvsFigureChoice.init();
} else if (iMenuChoice == MENU_HIGHSCORE) { //选择进入高分榜
if (frmHighScore == null) {
frmHighScore = new HighScoreForm(display);
}
display.setCurrent(frmHighScore);
frmHighScore.init();
} else if (iMenuChoice == MENU_SETTINGS) { //选择进入设置界面
if (frmSettings == null) {
frmSettings = new SettingsForm(display, this);
}
display.setCurrent(frmSettings);
} else if (iMenuChoice == MENU_HELP) { //选择进入帮助界面
if (frmHelp == null) {
frmHelp = new HelpList(display, this);
}
display.setCurrent(frmHelp);
} else if (iMenuChoice == MENU_ABOUT) { //选择进入关于界面
if (frmAbout == null) {
frmAbout = new AboutForm(display, this);
}
display.setCurrent(frmAbout);
} else if (iMenuChoice == MENU_EXITGAME){ //选择退出游戏
CardMainMIDlet.quitApp();
}
}
repaint();
}
public void paint(Graphics g) {
g.drawImage(imgMainMenu, 0, 0, Graphics.TOP | Graphics.LEFT);
g.setClip(iMenuX,iMenuY + iMenuChoice * 19, iMenuWidth, iMenuHeight);
g.drawImage(imgMenuChoice, 0, 0, Graphics.TOP | Graphics.LEFT);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -