13,100
社区成员
发帖
与我相关
我的任务
分享
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Start extends MIDlet {
public Start() {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
Display.getDisplay(this).setCurrent(new MyCanvas());
}
}
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class MyCanvas extends Canvas implements Runnable {
public MyCanvas() {
super();
// TODO Auto-generated constructor stub
try {
img = Image.createImage("/map.png");
w = img.getWidth();
h = img.getHeight();
temp = new int[w * h];
data = new int[w * h];
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Thread(this).start();
}
protected void paint(Graphics g) {
// TODO Auto-generated method stub
g.drawImage(img, 0, 0, 20);
g.drawImage(turn(img), w, 0, 20);
}
public void run() {
// TODO Auto-generated method stub
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Image turn(Image img) {
img.getRGB(temp, 0, w, 0, 0, w, h);
for (int i = w * h - 1; i > -1; i--) {
data[i] = temp[w - 1 - i % w + i / w * w];
}
img = Image.createRGBImage(data, w, h, false);
return img;
}
Image img = null;
int w;
int h;
int[] temp;
int[] data;
}