用java写的图片查看器运行时怎么没有图片显示出来丫
importjava.applet.Applet;importjava.awt.Choice;importjava.awt.Event;importjava.awt.Gr...
import java.applet.Applet;
import java.awt.Choice;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
public class PhotoAlbum extends Applet{
private Choice myChoice;
private String[] myString1,myString2;
private int totalPics;
private Image offI;
private Image[] img;
private Graphics offG;
private MediaTracker imagetracker;
public void init(){
this.setSize(600,450);
this.setLayout(null);
myChoice=new Choice();
myChoice.setBounds(10,10,290,20);
totalPics=8;
myString1=new String[totalPics];
myString2=new String[totalPics];
img=new Image[totalPics];
for(int i=0;i<totalPics;i++){
myString1[i]=new String("");
myString2[i]=new String("");
}
String s=new String("");
imagetracker=new MediaTracker(this);
for(int i=0;i<totalPics;i++){
s="第"+(i+1)+"张照片";
myString1[i]=s;
System.out.println(myString1[i]);
myChoice.addItem(s);
s=(i+1)+".jpg";
myString2[i]=s;
img[i]=getImage(getDocumentBase(),s);
imagetracker.addImage(img[i], 0);
}
try{
imagetracker.waitForID(0);
}catch (InterruptedException e){
}
add(myChoice);
offI=createImage(getSize().width,getSize().height-40);
offG=offI.getGraphics();
offI=img[0];
offG.drawImage(offI, 0, 0, this);
repaint();
}
public void paint(Graphics g){
g.drawImage(offI, 10, 40, this);
}
//使用action()方法来获得java applet小程序运行时所发生的事件
public boolean action(Event e,Object o){
if(e.target==myChoice){
String s=new String("");
offG.setColor(this.getBackground());
offG.fillRect(0, 40, getSize().width, getSize().height-40);
offI=img[myChoice.getSelectedIndex()];
offG.drawImage(offI, 0, 0, this);
repaint();
}
return true;
}
}
程序运行没有错误,就是没有图片。。。 展开
import java.awt.Choice;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
public class PhotoAlbum extends Applet{
private Choice myChoice;
private String[] myString1,myString2;
private int totalPics;
private Image offI;
private Image[] img;
private Graphics offG;
private MediaTracker imagetracker;
public void init(){
this.setSize(600,450);
this.setLayout(null);
myChoice=new Choice();
myChoice.setBounds(10,10,290,20);
totalPics=8;
myString1=new String[totalPics];
myString2=new String[totalPics];
img=new Image[totalPics];
for(int i=0;i<totalPics;i++){
myString1[i]=new String("");
myString2[i]=new String("");
}
String s=new String("");
imagetracker=new MediaTracker(this);
for(int i=0;i<totalPics;i++){
s="第"+(i+1)+"张照片";
myString1[i]=s;
System.out.println(myString1[i]);
myChoice.addItem(s);
s=(i+1)+".jpg";
myString2[i]=s;
img[i]=getImage(getDocumentBase(),s);
imagetracker.addImage(img[i], 0);
}
try{
imagetracker.waitForID(0);
}catch (InterruptedException e){
}
add(myChoice);
offI=createImage(getSize().width,getSize().height-40);
offG=offI.getGraphics();
offI=img[0];
offG.drawImage(offI, 0, 0, this);
repaint();
}
public void paint(Graphics g){
g.drawImage(offI, 10, 40, this);
}
//使用action()方法来获得java applet小程序运行时所发生的事件
public boolean action(Event e,Object o){
if(e.target==myChoice){
String s=new String("");
offG.setColor(this.getBackground());
offG.fillRect(0, 40, getSize().width, getSize().height-40);
offI=img[myChoice.getSelectedIndex()];
offG.drawImage(offI, 0, 0, this);
repaint();
}
return true;
}
}
程序运行没有错误,就是没有图片。。。 展开
1个回答
2015-07-22
展开全部
if(e.target==myChoice){ 不可以使用==比较对象,使用对象的equals来比较
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询