📄 mymenu.java
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import com.nokia.mid.ui.FullCanvas;
public class MyMenu extends FullCanvas
{
static PlayMusic p;
static boolean musicON = true;
//主画面
private static Displayable instance;
private Image back,ok;
public static void startMusic()
{
if(musicON)
{
if (p == null)
{
p = new PlayMusic();
p.Music_start("/res/gamestart.mid");
}
else
{
p.Music_start1();
}
}
}
//创建并得到主画面的对象
synchronized public static Displayable getInstance()
{
startMusic();
if(instance == null)
instance = new MyMenu();
return instance;
}
private Image zhu, help1, newgame1, count1,about1,setSound1;
int pressedButton=1;
//主画面构造函数,创建播放器并加入2个按钮
public MyMenu()
{
super();
setFullScreenMode(true);
back = null;
ok = null;
try
{
back = Image.createImage("/res/back.png");
ok = Image.createImage("/res/ok.png");
zhu = Image.createImage("/res/menu.png");
help1 = Image.createImage("/res/help1.png");
count1 = Image.createImage("/res/count1.png");
newgame1 = Image.createImage("/res/newgame1.png");
about1 = Image.createImage("/res/about1.png");
setSound1 = Image.createImage("/res/setSound.png");
}
catch (Exception e)
{
}
}
protected void paint(Graphics g)
{
g.setColor(0,0,0);
g.fillRect(0,0,getWidth(),getHeight());
//判断当时玩家所选项,并将选项用明显的按钮表现出来
g.drawImage(zhu, 0, 0, Graphics.TOP | Graphics.LEFT);
g.setColor(255,255,0);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_PLAIN,Font.SIZE_SMALL));
g.drawImage(back,getWidth(),getHeight(),Graphics.BOTTOM|Graphics.RIGHT);
g.drawImage(ok,0,getHeight(),Graphics.BOTTOM|Graphics.LEFT);
switch(pressedButton)
{
case 1:
g.drawImage(newgame1, 54, 105, Graphics.TOP | Graphics.LEFT);
break;
case 2:
g.drawImage(setSound1, 54, 105, Graphics.TOP | Graphics.LEFT);
break;
case 3:
g.drawImage(help1, 54, 105, Graphics.TOP | Graphics.LEFT);
break;
case 4:
g.drawImage(count1, 54, 105, Graphics.TOP | Graphics.LEFT);
break;
case 5:
g.drawImage(about1, 54, 105, Graphics.TOP | Graphics.LEFT);
break;
}
}
//按键选择事件,判断上下键来推断玩家现在所选择的按钮
public void keyPressed(int key)
{
switch(getGameAction(key))
{
case Canvas.UP:
pressedButton--;
if(pressedButton<1)
pressedButton = 5;
break;
case Canvas.DOWN:
pressedButton++;
if(pressedButton>5)
pressedButton = 1;
break;
}
if (key == -6)
{
switch(pressedButton)
{
case 1:
try
{
p.Music_close();
p = null;
}
catch (Exception e) {}
GameMenu.flow("开始");
break;
case 2:
GameMenu.flow("设置");
break;
case 3:
GameMenu.flow("帮助");
break;
case 4:
GameMenu.flow("得分");
break;
case 5:
GameMenu.flow("关于");
break;
}
}
if (key == -7)
{
try
{
p.Music_close();
p = null;
}
catch (Exception e) {}
GameMenu.flow("退出");
System.gc();
}
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -