Re: [問題] java裡怎麼用label顯示圖片
※ 引述《NightPrince (shooting star)》之銘言:
: ※ 引述《loveng (楓葉)》之銘言:
: : 在java裡使用awt套件
: : 顯示文字的話是Label lbl = new Label("Hello")
: : 那如果是要顯示圖片呢?
: : Label lb2 = new Label("000.jpg"); 是錯的,不能這樣寫
: : 因為這樣顯示出來的是000.jpg這文字,而不是圖片
: : 所以不知道要怎麼寫,請會的人教一下,謝謝喔^^
: .............................................
: 煩請多多查查API吧
: awt套件裡的 Label 類別,我沒看到可以傳一張圖片的檔案路徑
: 為參數的建構子
: 而且下面一段話擷取自 Label 的API:
: A Label object is a component for placing text in a container. A label
: displays a single line of read-only text. The text can be changed by the
: application, but a user cannot edit it directly.
: 也就是說他只能顯示文字而已
: swing裡面的 JLabel 才可以顯示圖片
: 至於用法....請去查查API吧
: http://java.sun.com/j2se/1.4.2/docs/api/
: 對了,順便說一下
: JLabel label = new JLabel("000.jpg");
: 這樣可是不行的喔
還是有點不懂~
但是我是有查到大概的語法
是這樣嗎?
JLabel starimage = new JLabel(new ImageIcon("000.jpg"));
可是圖片也是顯示不出來= =
如果知道的話可以幫我修正一下嗎
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.127.27.103
討論串 (同標題文章)