About applet question.

DragonGorden 2002-03-11 04:40:30
How can show a picture on a button of an applet application?
Such as
import java.applet.*;
import javax.swing.*;
public class B extends Applet
{
public void init()
{
Icon ic=new ImageIcon("C:\\WINDOWS\\SYSTEM\\OOBE\\IMAGES\\HNDSHAKE.JPG");
JButton b=new JButton(ic);
add(b);
}
}
...全文
44 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
rinehart 2002-03-13
  • 打赏
  • 举报
回复
to DragonGorden(龙) :
你先随便找本java的书,好好看看关于applet的章节,然后再写程序。

你觉得我写了一堆代码和这两句实现的功能是一致的是么?
Icon ic=new ImageIcon ("HNDSHAKE.JPG");
JButton b=new JButton(ic);

呵呵......我还没到弃简求繁的状态呢!
你先搞清楚sandbox,数字签名吧!
rinehart 2002-03-12
  • 打赏
  • 举报
回复
import java.applet.*;
import java.net.*;
import javax.swing.*;
import java.awt.*;

public class B extends Applet
{
public void init()
{
try {
URL tempURL = getCodeBase();
Toolkit tk = Toolkit.getDefaultToolkit();
URL tureURL = new URL(tempURL,"HNDSHAKE.JPG");
System.out.println(tureURL);
Image img = tk.getImage(tureURL);
JButton b=new JButton();
b.setIcon(new ImageIcon(img));
this.add(b);
} catch (Exception e) {
System.out.println(e);
}
}
}
remote_roamer 2002-03-12
  • 打赏
  • 举报
回复
Applet can not read the local files .
DragonGorden 2002-03-12
  • 打赏
  • 举报
回复
To whyyy78:
getResource()的括号是否图片的全路径名
但:
Runtime Error.
whyyy78 2002-03-12
  • 打赏
  • 举报
回复
这样可以:
JButton exitbut=new JButton(new ImageIcon(getClass().getResource("images/exit.gif")));
DragonGorden 2002-03-12
  • 打赏
  • 举报
回复
rinehart:
Think you for your help.
But you know,there is an easy way to do that if the
picture("HNDSHAKE.JPG") at the same path of the B.class file:

import java.applet.*;
import javax.swing.*;
public class B extends Applet
{
public void init()
{
Icon ic=new ImageIcon ("HNDSHAKE.JPG");
JButton b=new JButton(ic);
add(b);
}
}
If not at the same path of *.class file.How can I do?
DragonGorden 2002-03-11
  • 打赏
  • 举报
回复
Error message is:
java.security.AccessControlException: access denied (java.i
INDOWS\SYSTEM\OOBE\IMAGES\HNDSHAKE.JPG read)
at java.security.AccessControlContext.checkPermissi
xt.java:272)
at java.security.AccessController.checkPermission(A
399)
at java.lang.SecurityManager.checkPermission(Securi
at java.lang.SecurityManager.checkRead(SecurityMana
at sun.awt.SunToolkit.getImageFromHash(SunToolkit.j
at sun.awt.SunToolkit.getImage(SunToolkit.java:280)
at javax.swing.ImageIcon.<init>(ImageIcon.java:77)
at javax.swing.ImageIcon.<init>(ImageIcon.java:103)
at B.init(B.java:8)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)
rinehart 2002-03-11
  • 打赏
  • 举报
回复
程序没问题!
你最好把错误信息写出来!
DragonGorden 2002-03-11
  • 打赏
  • 举报
回复
There are some Runtime Error at above question.
How can I resolve them?

23,407

社区成员

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

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