|
classpath:E:\JBuilder\jdk1.4\lib\tools.jar;E:\JBuilder\jdk1.4\lib\dt.jar;.
工程路径:D:\javawork\j2me\SlideshowMidlet
图片存放位置:D:\javawork\j2me\SlideshowMidlet\
程序在JBuilder中编写,编译,运行
在运行的时候,抛出异常:Failed loading images!
源程序代码如下:(有二个类,运行类没有发上来)
import javax.microedition.lcdui.*;
import java.io.*;
public class SSCanvas extends Canvas {
private Display display;
private Image [] slides;
private String [] captions = {"A","B","C","D","E"};
private int curSlide = 0;
public SSCanvas(Display d){
super();
display = d;
//图片加载程序开始
try {
slides = new Image[5];
slides[0] = Image.createImage("/A.gif");
slides[1] = Image.createImage("/B.gif");
slides[2] = Image.createImage("/C.gif");
slides[3] = Image.createImage("/D.gif");
slides[4] = Image.createImage("/E.gif");
} catch (IOException e) {
System.err.println("Failed loading images!");
}//图片加载结束
}
void start(){
display.setCurrent(this);
repaint();
}
public void keyPressed(int keyCode){
int action =getGameAction(keyCode);
switch(action){
case LEFT:
if(-- curSlide < 0 ){
curSlide = slides.length - 1;
}
repaint();
break;
case RIGHT:
if(++ curSlide >= slides.length){
curSlide = 0;
}
repaint();
break;
}
}
public void paint(Graphics g){
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
g.drawImage(slides[curSlide],getWidth()/2,getHeight()/2,Graphics.HCENTER | Graphics.VCENTER);
Font f = Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM);
g.setFont(f);
g.setColor(0,0,0);
g.drawString(captions[curSlide],getWidth()/2,0,Graphics.HCENTER | Graphics.TOP);
}
} |
|