import java.awt.*;
import javax.swing.*;import java.awt.event.*;
public class MyAppletImage extends JApplet{
private String[]fileNames={"1.gif","2.gif","3.gif","4.gif"};
private JComboBox com=new JComboBox(fileNames);
private ImagePanel imagePanel =new ImagePanel();
private String name=fileNames[0];
private Image image;
public void init()
{
image=getImage(getCodeBase(),name);
com.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e)
{
JComboBox cb=(JComboBox)e.getSource();
int i=cb.getSelectedIndex();
name=fileNames[i];
image=getImage(getCodeBase(),name);
repaint();
}
});
setLayout(new BorderLayout());
add(imagePanel,BorderLayout.CENTER);
add(com,BorderLayout.NORTH);
}
class ImagePanel extends JPanel
{
public void painComponent(Graphics g)
{
super.paintComponent(g);
if(image!=null)
g.drawImage(image,0,0,getWidth(),getHeight(),this);
}
}}我图片和applet是放在同一个目录里面的。