按钮上图片为何显示不出来

freetide 2004-06-25 03:03:02
这是我在jb9中输入的一段代码可以运行,
这是按钮上的图片没有显示
图片文件与java源文件放在一个目录下,
是不是要在jb9下做什么设置啊?
//ToolBar.java

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

public class ToolBar extends JFrame{
public ToolBar(){
super("ToolBar Demo");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon image1=new ImageIcon("button1.gif");
JButton button1=new JButton(image1);
ImageIcon image2=new ImageIcon("button2.gif");
JButton button2=new JButton(image2);
ImageIcon image3=new ImageIcon("button3.gif");
JButton button3=new JButton(image3);
JToolBar bar=new JToolBar();
bar.add(button1);
bar.add(button2);
bar.add(button3);
JTextArea edit=new JTextArea(8,40);
JScrollPane scroll=new JScrollPane(edit);
JPanel pane=new JPanel();
BorderLayout bord=new BorderLayout();
pane.setLayout(bord);
pane.add("North",bar);
pane.add("Center",scroll);

setContentPane(pane);

}

public static void main(String[] arguments){
ToolBar frame=new ToolBar();
frame.pack();
frame.setVisible(true);
}
}
...全文
207 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
BigBangBug 2004-06-25
  • 打赏
  • 举报
回复
路径问题,
ImageIcon image1=new ImageIcon("button1.gif");
改成
ImageIcon image1=new ImageIcon("\\button1.gif");

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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