📄 selectcanvas.java
字号:
/*
* 创建日期 2006-3-20
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package catchElephent;
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
/**
* @author as
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class SelectCanvas extends GameCanvas implements Runnable {
Graphics g=this.getGraphics();
ElephentMIDP elephentMIDP;
IntroduceGameCanvas introduce;
StartGameCanvas startgame;
Image Ibackground;
String[] list={"游戏简介","游戏开始","退出"};
int i=0;
boolean Bquit;
/**
* @param elephentMIDP
*/
public SelectCanvas(ElephentMIDP elephentMIDP) {
super(true);
this.elephentMIDP=elephentMIDP;
try {
// TODO 自动生成构造函数存根
Ibackground=Image.createImage("/background.png");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
introduce=new IntroduceGameCanvas(this);
startgame=new StartGameCanvas(this);
g.drawString(list[i],this.getWidth()/2,this.getHeight()-getHeight()/3,Graphics.LEFT|Graphics.TOP);
Thread thread=new Thread(this);
thread.start();
}
/* (非 Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
// TODO 自动生成方法存根]
int R=0;
int G=0;
int B=0;
while(!Bquit){
R++;
G++;
B++;
if(R==255||G==255||B==255){
R=0;
B=0;
G=0;
}
g.drawImage(Ibackground,0,0,Graphics.LEFT|Graphics.TOP);
g.setColor(255-R,G,255-B);
g.drawString(list[i],this.getWidth()/2-10,this.getHeight()-getHeight()/3,Graphics.LEFT|Graphics.TOP);
g.drawString("制作人:徐多猛",this.getWidth()/2+30,this.getHeight()-getHeight()/3+80,Graphics.LEFT|Graphics.TOP);
flushGraphics();
int key=getKeyStates();
if((key&DOWN_PRESSED)!=0){
if(i<2){
i++;
}
}else{
if((key&UP_PRESSED)!=0){
if(i>0){
i--;
}
}else{
if((key&RIGHT_PRESSED)!=0){
switch(i){
case 0:
elephentMIDP.display.setCurrent(introduce);
introduce.start();
break;
case 1:
elephentMIDP.display.setCurrent(startgame);
startgame.start();
break;
case 2:
Bquit=true;
break;
}
}
}
}
try {
Thread.sleep(60);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
elephentMIDP.Bquit=true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -