mac系统 代码中使用相对路径 文件应该放在哪里

杨夜夜 2017-12-25 11:25:59
网上说应该放在和.class在一个文件夹里,默认的也就是bin文件夹
我想使用一张图片
把这张图片放在bin文件夹里依旧不显示

代码是这样的,只是写的很初步的代码

package gui_TTT;
import javax.swing.*;
import java.awt.*;

public class Gui_TTT extends JFrame{

Gui_TTT(){
super("TicTacToe");
this.setSize(500,500);
this.setLocationRelativeTo(null);
this.getContentPane().setLayout(null);
ImageIcon ttt = new ImageIcon("ttt.jpg");
JLabel jl = new JLabel(ttt);
jl.setBounds(0, 0, ttt.getIconWidth(),ttt.getIconHeight());
this.getContentPane().add(jl);

this.setVisible(true);
}
public static void main(String[] args) {
Gui_TTT game = new Gui_TTT();
game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}
...全文
1484 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hp961218 2017-12-26
  • 打赏
  • 举报
回复
好像相对路径都是以src为相对,或者webApp为相对,图片应该可以直接放到src下面进行读取.

58,453

社区成员

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

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