0
任何人都可以帮我把图片加载到JLabel中? ATM不识别ImageIO。找不到变量ImageIO
private void doAnimation (int frame)
{
String str = Integer.toString(frame);
String selFrame = "f"+ str + ".png";
BufferedImage wPic = ImageIO.read(this.getClass().getResource(selFrame));
JLabel wIcon = new JLabel(new ImageIcon(wPic));
add(wIcon);
JLabel picLabel = new JLabel(new ImageIcon(wPic));
add(picLabel);
}
selFrame是使用定时器生成的png文件的名称。 Frame是在应用程序中使用时导入到函数中的数字。
这里是ActionListener的
if (actionEvent.getSource() == timerBackground)
{
if (backgroundNum == 42) backgroundNum = 1;
doAnimation(backgroundNum);
backgroundNum++;
}
这里的计时器是在构造函数激活的定时器
timerBackground = new javax.swing.Timer (200, this);
有42个不同的框架(从一个gif->我分解成帧,并想要做一个动画) –