簡體   English   中英

ImageIcon 不會在 JLabel 中顯示

[英]ImageIcon won't display in JLabel

我一直在嘗試將圖像圖標用於我的口袋妖怪游戲,在您選擇它們時顯示每個開始的圖像。 但是,當我運行我的程序時,圖像不會顯示,但它不會引發錯誤。 該圖像位於 src 文件夾中名為 images 的文件夾中。 我一直在自己學習 Swing 很好,但是這個問題難倒了我。

public ImageIcon f = new ImageIcon("images/bulbasaur.png"); //declared in the bulbasaur class

Bulbasaur bulb = new Bulbasaur(1, "Bulbasaur", 5);    // declared in the main class
final JLabel test = new JLabel();
test.setIcon(bulb.f);
test.setVisible(true);

Java 可能無法找到具有給定路徑的圖像我會嘗試更改您的第一行

public ImageIcon f = new ImageIcon(Bulbasaur.class.getResource("images/bulbasaur.png"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM