ImageIcon将不会显示在JLabel中

问题描述 投票:-1回答:1

我一直在尝试在我的神奇宝贝游戏中使用图像图标,方法是在选择每个开始时显示每个开始的图像。但是,该图像在我运行程序时不会显示,但不会引发错误。该图像位于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 swing jlabel imageicon
1个回答
0
投票

Java可能无法找到具有给定路径的图像,我会尝试更改您的第一行

public ImageIcon f = new ImageIcon(Bulbasaur.class.getResource("images/bulbasaur.png"));
© www.soinside.com 2019 - 2024. All rights reserved.