问题描述
importjava.io.IOException;importjavax.microedition.lcdui.Canvas;importjavax.microedition.lcdui.Display;importjavax.microedition.lcdui.Graphics;importjavax.microedition.lcdui.Image;importjavax.microedition.midlet.MIDlet;importjavax.microedition.midlet.MIDletStateChangeException;publicclassMIDletTestextendsMIDlet{privateDisplaydis;privateCanvasTcc;privateImageimg;publicMIDletTest(){try{img=Image.createImage("/cow.jpg");}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}cc=newCanvasT();}protectedvoidstartApp()throwsMIDletStateChangeException{dis=Display.getDisplay(this);dis.setCurrent(cc);}protectedvoidpauseApp(){//TODOAuto-generatedmethodstub}protectedvoiddestroyApp(booleanarg0)throwsMIDletStateChangeException{//TODOAuto-generatedmethodstub}classCanvasTextendsCanvas{privateGraphicsg=null;publicvoidpaint(Graphicsarg0){g=arg0;System.out.println("paint()执行");g.drawLine(0,0,300,200);}publicvoidkeyRepeated(intkeyCode){intaction=getGameAction(keyCode);System.out.println(action);if(action==Canvas.FIRE){System.out.println("keyRepeated()执行");g.drawLine(0,0,50,100);}}}}
解决方案
解决方案二:
你用flex画图多好
解决方案三:
该回复于2011-03-29 09:35:22被版主删除
解决方案四:
是画过了,但是没有画到画布上,你在按键事件里面的g.drawLine()方法后调用一下repaint()就可以了
解决方案五:
绘图工作一般是由paint完成,用双缓冲的机理publicclassCanvasMainextendsCanvas{//离屏画布privateImageoffScreen;//离屏画笔privateGraphicsoffGra;publicCanvasMain(){this.setFullScreenMode(true);//创建与屏幕尺寸相同的离屏画布offScreen=Image.createImage(this.getWidth(),this.getHeight());//获取离屏画布画笔offGra=offScreen.getGraphics();this.drawUI();}privatevoiddrawUI(){offGra.setColor(0xccaaff);offGra.fillRect(0,0,this.getWidth(),this.getHeight());}protectedvoidpaint(Graphicsg){g.drawImage(offScreen,0,0,Graphics.LEFT|Graphics.TOP);}}
解决方案六:
结构有点问题,呵呵,直接把x,y值写入,调用repaint,再绘制,修改的地方只是在paint函数里面。