[問題] JPanel 放圖的路徑
public class Image2 extends JPanel{
private BufferedImage image;
public Image2(){
try{
image = ImageIO.read(new File("123.jpg"));
repaint();
}
catch(IOException ex){
System.out.print("no image!!");
}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(image,0,0,null);
}
我想將一個叫做123.jpg的檔放到PANEL裡
然後把123.jpg跟檔案放在相同資料夾裡
可是會一直讀不到 ( catch到exception 顯示 no image)
一定得用絕對路徑才能讀到 這樣圖片檔的位子就被鎖死@@
想請教一下該怎麼辦才能辦到 把123.JPG跟檔案放在同一資料夾就能夠成功丟進 panel
感謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.221.161
推
10/27 21:51, , 1F
10/27 21:51, 1F