用canvas制作显示图片的画面,有问题,附代码,帮忙分析一下,
简单地说,就是用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);
        }
};

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭