gpt4 book ai didi

java - 改变 Jframe 图像

转载 作者:行者123 更新时间:2023-12-01 11:03:00 25 4
gpt4 key购买 nike

所以我很难实现 Jframe 图像/图标的更改。我正在使用 for 循环,并希望将 Jframe 的图像更改为我检索到的相应图像,但我要么让它卡在第一帧,要么它们只是相互堆积。我在网上查看过,但他们只展示了如何最初更改 Jframe,而不是在 for 循环中。

这是我的代码的一部分:

JFrame frame = new JFrame();

for(int frameNum = 0; frameNum < fg.getLengthInFrames(); frameNum++) {

ImageIcon icon = new ImageIcon(img);
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // close canvas once the window is closed
frame.pack();
frame.setVisible(true);

}

最佳答案

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Test{
public static void main(String[] args) {
for(int frameNum = 0; frameNum <=4; frameNum++) {
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("G:/Skypecartoons/we.jpg");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // close canvas once the window is closed
frame.pack();
frame.setVisible(true);
}
}


}

关于java - 改变 Jframe 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33196570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com