Menu.java
上传用户:public
上传日期:2010-01-27
资源大小:484k
文件大小:2k
- package GameDisplay;
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.Displayable;
- import java.io.*;
- public class Menu extends Canvas {
- private int cx=0;//cx,cy是画的位置
- private int cy=0;
- private int buttonId=0;//按钮的号
- private int w=0;
- private int h=0;
- private int d=5;
- private Image backImg;
- private Image curImg;
- public Menu(){ //构造函数
- w=this.getWidth();
- h=this.getHeight();
- try {
- backImg = Image.createImage("/res/welcome.jpg");
- curImg=Image.createImage("/res/cursor.png");
- }
- catch (IOException ex) {
- }
- cx=(w-backImg.getWidth())/2;
- cy=(h-backImg.getHeight())/2;
- }
- public void paint(Graphics g) {
- g.setColor(0x000000);
- g.fillRect(0,0,w,h);
- g.drawImage(backImg,cx,cy,Graphics.LEFT|Graphics.TOP);
- g.drawImage(curImg,cx+40,cy+22*(buttonId+1)+30,Graphics.LEFT|Graphics.TOP);
- }
- private void keyUp(){
- if(buttonId<=0){ buttonId=0; }
- else{buttonId--;}//测开始等按钮的位置
- }
- private void keyDown(){
- if(buttonId>=d-1){ buttonId=d-1; }
- else{buttonId++;}//测开始等按钮的位置
- }
- private void keyFire(){//选择按钮
- switch(buttonId)
- {
- case 0://进入游戏
- Control.showChoiceLevel();
- break;
- case 1://读高分榜
- Control.showHighRecord();
- break;
- case 2://帮助——HelpBox
- Control.showHelp();
- break;
- case 3://关于——AboutBox
- Control.showAbout();
- break;
- case 4://退出——quitApp
- Control.quitApp();
- break;
- default:
- break;
- }//end switch comid
- }
- //////////////////////////////////////////////////////////////////
- public void keyPressed(int keyCode)//系统自动侦听按钮
- {
- switch(getGameAction(keyCode))
- {
- case Canvas.UP:
- { keyUp(); break; }
- case Canvas.DOWN:
- {keyDown(); break; }
- case Canvas.FIRE:
- {keyFire(); break;//Canvas.FIRE
- }
- }//end switch keycode
- repaint();
- }//end keypressed
- }