📄 mycanvas.java
字号:
package bluetoochgame;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.media.*;
import javax.microedition.io.*;
import java.util.Vector;
public class MyCanvas extends Canvas
implements Runnable, CommandListener {
public static String name;
boolean slepping;
boolean newGame; //是否是新的游戏
Display display;
private GameWorld gameworld;
public Connection connection;
private Control control;
public void start() {
display.setCurrent(this);
gameworld = new GameWorld();
//' control = new Control(gameworld);
// connection = new Connection(control);
// connection.start() ;//连接开始
gameworld.start() ;
Thread t = new Thread(this);
t.start();
}
public MyCanvas(Display display,String name) {
this.name = name;
slepping = false;
this.display = display;
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
addCommand(new Command("Restart", Command.SCREEN, 1));
}
/**Handle command events*/
public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
if (command.getLabel().equals("Exit")) {
// stop the MIDlet
BTGame.quitApp();
}
if (command.getLabel().equals("Restart")) {
}
}
protected void keyPressed(int keycode)
{
gameworld.keyPressed(getGameAction(keycode));
}
public void run() {
while (!slepping) {
repaint();
// serviceRepaints();
try {
Thread.sleep(100);
}
catch (InterruptedException ie) {}
}
}
public void paint(Graphics g)
{
g.setColor(0x00000000);
g.fillRect(0, 0, getWidth(), getHeight());
gameworld.draw(g) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -