模拟器显示不出来东西?
运行通过 但是模拟器显示不出来东西 不知道是怎么回事 请各位看看 谢谢!
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.MIDletStateChangeException;
import java.util.*;
import *;
public class SlideShowMidlet extends MIDlet {
private SSCanvas canvas;
public SlideShowMidlet() {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
canvas.stop();
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
if(canvas == null)
{
canvas = new SSCanvas(Display.getDisplay(this));
/*Command exitCommand = new Command("Exit",Command.EXIT,0);
canvas.addCommand(exitCommand);
canvas.setCommandListener(this);
*/
}
canvas.Start();
}
/*public void commandAction(Command c,Display s)
{
if(c.getCommandType() == Command.EXIT)
{
canvas.stop();
notifyDestroyed();
}
}
*/
}
class SSCanvas extends GameCanvas implements Runnable
{
private Display display;
private boolean sleeping;
private long frameDelay;
private Random rand;
private Sprite dongSprite;
private int dongXSpeed,dongYSpeed;
public SSCanvas(Display d)
{
super(true);
display = d;
frameDelay = 33;
}
public void Start()
{
display.setCurrent(this);
rand = new Random();
dongXSpeed = dongYSpeed = 3;
try
{
dongSprite = new Sprite(Image.createImage("/Character_06_B.png"));
dongSprite.setPosition(0, 0);
}
catch(IOException ex)
{
System.err.println("Failde loading image!");
}
sleeping = false;
Thread t =new Thread(this);
t.start();
}
public void stop()
{
sleeping = true;
}
public void run()
{
Graphics g = getGraphics();
while(!sleeping)
{
update();
draw(g);
try
{
Thread.sleep(frameDelay);
}
catch(InterruptedException ex)
{}
}
}
private void update()
{
if(rand.nextInt()%5 == 0)
{
dongXSpeed = Math.min(Math.min(dongXSpeed+rand.nextInt()%2, -8),8);
dongYSpeed = Math.min(Math.min(dongYSpeed+rand.nextInt()%2, -8),8);
}
dongSprite.move(dongXSpeed, dongYSpeed);
}
private void draw(Graphics g)
{
g.setColor(0x00000000);
g.fillRect(0, 0, getWidth(), getHeight());
dongSprite.paint(g);
flushGraphics();
}
}