34. 阅读下列程序,请写出该程序的功能。假定图像文件apple.gif、banana.gif、pear.gif和watermelon.gif已经存放在当前目录中。
import java. awt. *;import java. awt. event. *;import javax. swing. *;
public class Test3 4 extends JApplet implements ItemListener{
Image image=null;
JPanel p;
public void init() {
Container contentPane=getContentPane();
contentPane. setLayout(new FlowLayout());
JComboBox jc=new JComboBox();
jc. addItem("apple");jc. addItem("banana");
jc. addItem("pear"); jc. addItem("watermelon");
jc. addItemListener(this);
contentPane. add(jc);
p=new JPanel( );
contentPane. add(p);
}
public void paint(Graphics g){
if(image!=null)
g. drawlmage(image,0,0,this);
}
public void itemStateChanged(ItemEvent ie){
String s=(String)ie. Getltem();
image=getImage(getCodeBase(),s+". gif");
repaint();
}
}