将canvas创建高级菜单(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:34 点击:次
// Get Width and Height of Canvas
width = getWidth();
height = getHeight();
setFullScreenMode(true);
menuIdx = 0;
g = getGraphics();
leftOption = "Options";
rightOption = "Exit";
menu = new Menu(leftOption, rightOption, menuOptions);
start();
midlet.display.setCurrent(this);
}
public void start() {
clearScreen();
menu.drawInactiveMenu(this, g);
}
public void clearScreen() {
g.setColor(0xffffff); // white
g.fillRect(0, 0, width, height);
flushGraphics();
}
protected void keyPressed(int keyCode) {
if (menuIsActive) {
if (keyCode == RIGHT_SOFTKEY_CODE) {
// draw inactive menu again
clearScreen();
menu.drawInactiveMenu(this, g);
menuIsActive = false;
}
keyCode = getGameAction(keyCode);
if (keyCode == UP) {
currentlySelectedIndex--;
if (currentlySelectedIndex < 0) {
currentlySelectedIndex = 0; // stay within limits
}
menu.drawActiveMenu(this, g, currentlySelectedIndex);
}
else if (keyCode == DOWN) {
currentlySelectedIndex++;
if (currentlySelectedIndex >= menuOptions.length) {
currentlySelectedIndex = menuOptions.length - 1;
}
menu.drawActiveMenu(this, g, currentlySelectedIndex);
}
else if (keyCode == FIRE) {
clearScreen();
g.setColor(0x000000);
g.drawString("[" + menuOptions[currentlySelectedIndex]
+ "] was selected", 10, 15, g.LEFT | g.TOP);
menu.drawInactiveMenu(this, g);
menuIsActive = false;
}
}
else {
if (keyCode == LEFT_SOFTKEY_CODE) { // "Options" pressed
menu.drawActiveMenu(this, g, currentlySelectedIndex);
menuIsActive = true;
}
else if (keyCode == RIGHT_SOFTKEY_CODE) {
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>