j2me图片显示出不来

chinahunter 2003-10-09 10:36:06
package movepic;

import javax.microedition.lcdui.*;

public class moviepic extends Canvas implements CommandListener {
/** Constructor */
Image img;
public moviepic() {
try {
// img= Image.createImage("/phone.png");
img= Image.createImage("/phone.png");
jbInit();
// moviepic.paint(img);
}
catch(Exception e) {
e.printStackTrace();
}

}




/* public void paint(Graphics g){
int x, y;
//Graphics g;
g = img.getGraphics();
x = g.getClipX();
y = g.getClipY();
g.drawImage(img, x, y, Graphics.LEFT | Graphics.TOP);
}
*/


/**Component initialization*/
private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
}

/**Handle command events*/
public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
if (command.getCommandType() == Command.EXIT) {
// stop the MIDlet
MIDlet1.quitApp();
}
}

/** Required paint implementation */
protected void paint(Graphics g) {

g.drawImage(img, 10,10, Graphics.LEFT | Graphics.TOP);

}

}
...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
CD2 2003-10-10
  • 打赏
  • 举报
回复
JB没有用过,我的破机器不行啊!不知道他是怎么自动生成这么多代码,首先看一下你的代码问题:
一:一个MIDlet必须继承MIDlet
二:Image img//这里要初始化
三:一个MIDlet需要有生命周期,我找不到你的startApp(),pauseApp(),destroyApp方法
我用记事本写了一个你需要实现的代码,我把不需要的部分都已经注释掉了,如下(调试通过):
//moviepic.java
------------------------------------------------
import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;

public class moviepic extends Canvas{//implements CommandListener
/** Constructor */
//Display display;
Image img=null;
//public void startApp(){
//display=Display.getDisplay(this);
//display.setCurrent(this);
//}
// public void pauseApp(){}
//public void destroyApp(boolean unconditional){
//notifyDestroyed();
// }
public moviepic() {
if(img==null){
try {
//img= Image.createImage("/phone.png");
img= Image.createImage("/JavaPowered.png");
//jbInit();
// moviepic.paint(img);
}
catch(Exception e) {
e.printStackTrace();
}

}
}





/* public void paint(Graphics g){
int x, y;
//Graphics g;
g = img.getGraphics();
x = g.getClipX();
y = g.getClipY();
g.drawImage(img, x, y, Graphics.LEFT | Graphics.TOP);
}
*/


/**Component initialization*/
//public void jbInit() throws Exception {
// Set up this Displayable to listen to command events
//setCommandListener(this);
// add the Exit command
//addCommand(new Command("Exit", Command.EXIT, 1));
//}

/**Handle command events*/
//public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
//if (command.getCommandType() == Command.EXIT) {
// stop the MIDlet
//MIDlet1.destroyApp();
//}
//}

/** Required paint implementation */
public void paint(Graphics g) {

g.drawImage(img, 10,10, Graphics.LEFT + Graphics.TOP);

}

}
---------------------------------------------------------
//Drawmoviepic.java
---------------------------------------------------
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Drawmoviepic extends MIDlet implements CommandListener{
Command cmdExit;
public Drawmoviepic(){
cmdExit=new Command("Exit",Command.EXIT,1);
}
protected void startApp()throws MIDletStateChangeException{
moviepic m;
m=new moviepic();
m.addCommand(cmdExit);
m.setCommandListener(this);
Display.getDisplay(this).setCurrent(m);
}
protected void pauseApp(){
}
protected void destroyApp(boolean unconditional)throws MIDletStateChangeException{
}
public void commandAction(Command c,Displayable d){
if(c==cmdExit){
try{destroyApp(false);
}catch(Exception e){}
notifyDestroyed();
}
}
}
不知不觉就4点了,哎!什么都没做,又浪费了一个晚上。晚安,我开了一个群,1445969,加入大家一起研究j2me.晚安
CD2 2003-10-10
  • 打赏
  • 举报
回复
给分:)
chinahunter 2003-10-10
  • 打赏
  • 举报
回复
已经解决了.
chinahunter 2003-10-09
  • 打赏
  • 举报
回复
其实就加了
img= Image.createImage("/phone.png");


protected void paint(Graphics g) {

g.drawImage(img, 10,10, Graphics.LEFT | Graphics.TOP);

}
这三句,其他都是jbuilder自动生成的
能编译运行
只是不显示图片,而手机屏幕上显示“application error"

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧