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);
}
}