| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1560 人关注过本帖
标题:模拟器显示不出来东西?
取消只看楼主 加入收藏
oldbabyxixi
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2007-9-16
收藏
 问题点数:0 回复次数:1 
模拟器显示不出来东西?
运行通过 但是模拟器显示不出来东西 不知道是怎么回事
请各位看看 谢谢!

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();
    }
}
搜索更多相关主题的帖子: import microedition javax 模拟 public 
2008-05-04 17:17
oldbabyxixi
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2007-9-16
收藏
得分:0 
我是觉得路径应该有问题 我是把图片放在桌面上的 请问应该怎样获取绝对路径了?谢谢!!
2008-05-05 21:41
快速回复:模拟器显示不出来东西?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026682 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved