一个简单的剪切图片
怎么运行的时候没有结果,手机模拟器也不出来了,什么情况 初学 着求帮助import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
public class GameCanvas extends Canvas implements Runnable {
private int spf = 1000 / 25;
private Image testImg;
public GameCanvas(MIDlet midlet) {
this.setFullScreenMode(true);
Thread thread = new Thread(this);
thread.start();
try {
testImg = Image.createImage("/0_map_0_cao3.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void paint(Graphics g) {
// TODO Auto-generated method stub
//...
// g.drawString("test", 30, 10, 0);
//
// g.drawImage(testImg, 100, 100, 0);
g.drawRegion(testImg, 0, 0, 16, 16,0, 0, 0, 0);//1
//
}
@Override
public void run() {
while (true) {
long timeStart = System.currentTimeMillis();
repaint();
serviceRepaints();
long timeTaken = System.currentTimeMillis() - timeStart;
long sleepTime = spf - timeTaken;
if (sleepTime > 0) { //若小于1000 / FPS,等待剩余时间
try {
Thread.sleep(sleepTime);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
public void keyPressed(int keyCode) {
}
public void keyReleased(int keyCode) {
}
}
J2ME --------------------编程问答-------------------- 还有 那个是Midlet
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Midlet extends MIDlet {
public Midlet() {
GameCanvas gc = new GameCanvas(this);
Display.getDisplay(this).setCurrent(gc);
}
@Override
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
@Override
protected void pauseApp() {
}
@Override
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
补充:Java , J2ME