关闭

用canvas制作显示图片的画面,有问题,附代码,帮忙分析一下,

50人阅读 评论(0) 收藏 举报
简单地说,就是用canvas显示一个画面,总是无法显示,环境是jbuilderx,错误提示,如下
java.lang.IllegalArgumentException

at midpda.MyCanvas.paint(+48)

at javax.microedition.lcdui.Canvas.callPaint(+80)

at javax.microedition.lcdui.Display.repaint(+77)

at javax.microedition.lcdui.Display.registerNewCurrent(+237)

at javax.microedition.lcdui.Display.access$400(+6)

at javax.microedition.lcdui.Display$DisplayAccessor.foregroundNotify(+46)

at javax.microedition.lcdui.Display$DisplayManagerImpl.notifyWantsForeground(+152)

at javax.microedition.lcdui.Display$DisplayManagerImpl.access$100(+6)

at javax.microedition.lcdui.Display.setCurrentImpl(+98)

at javax.microedition.lcdui.Display.setCurrent(+29)

at midpda.Displayable1.startApp(+28)

at javax.microedition.midlet.MIDletProxy.startApp(+7)

at com.sun.midp.midlet.Scheduler.schedule(+270)

at com.sun.midp.main.Main.runLocalClass(+28)

at com.sun.midp.main.Main.main(+116)

源程序如下
=============================================

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class Displayable1 extends MIDlet
{
        private Display display1;

        public Displayable1(){
        }

        public void startApp(){
                display1=Display.getDisplay(this);
                //创建MyCanvas对象,并将其设置为当前要显示的屏幕
                MyCanvas canvas = new MyCanvas(display1);
                display1.setCurrent(canvas);
        }

        public void pauseApp(){
        }

        public void destroyApp(boolean unconditional){
        }
}
//MyCanvas继承了Canvas类
class MyCanvas extends Canvas
{
  private Display display;
       public MyCanvas(Display dis){
         this.display=dis;
       }
        //绘图方法
        protected void paint(Graphics g1){
                //将绘图颜色设置为白色
           /*     g.setColor(255,255,255);
                //用当前绘图颜色填充整个屏幕
                g.fillRect(0,0,getWidth(),getHeight());
                //将绘图颜色设置为红色
                g.setColor(255,0,0);
                //用当前绘图颜色绘制字符串"Hello World"
//                g.drawString("Hello World",10,10,Graphics.LEFT|Graphics.TOP);*/
            int w=this.getWidth();
            int h=this.getHeight();
            Image b=null;
           try{
              b = Image.createImage("/ack8.png");
           }catch(Exception e){
             e.printStackTrace();
             
           }
                 g1.drawImage(b,w/2,h/2,Graphics.HCENTER);
        }
};

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1743次
    • 积分:227
    • 等级:
    • 排名:千里之外
    • 原创:22篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章存档
    最新评论