请问如何在Applet中显示图片?

ivenz 2004-01-30 01:19:55
好心人,请问如何在Applet中显示图片?程序如下,使用JBuilder编译成class后,使用网页调用,无法正常执行。请帮忙!

import javax.swing.*;
import java.net.*;
import java.awt.*;

public class test
extends JApplet{
JLabel imageLabel=new JLabel();
JPanel contentPane;

public test() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception
{
String fileName="back.jpg";
URL codeBase=null;
URL url=null;
codeBase=getCodeBase() ;

contentPane=(JPanel) this.getContentPane() ;
contentPane.setLayout(new GridLayout(1,1));
contentPane.add(imageLabel);

Image image=getImage(codeBase,"back.jpg");

Icon icon;
icon=new ImageIcon(image);

imageLabel.setIcon(icon) ;
imageLabel.setText("显示图片") ;
}
}
...全文
43 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wawaxp 2004-02-02
  • 打赏
  • 举报
回复
图片的路径是否正确?
如果路径错误是可以编译通过,
但是网页调用的时候就会出错了,
----

62,616

社区成员

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

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