Java 切换不同URL以切换GIF动画时出现问题

Java 切换不同URL以切换GIF动画时出现问题,java,swing,url,animated-gif,Java,Swing,Url,Animated Gif,我正在创建一个类似街头斗士的游戏,当游戏获胜时,我很难更改GIF动画。当JProgressBar等于0时,我更改了URL,但它什么也不做。如果有人可以帮助解决此问题,请提前感谢 public class Player1 { static JButton playerPunch = new JButton("Punch"); static JButton playerKick = new JButton("Kick"); static JButton playerSpecial = ne

我正在创建一个类似街头斗士的游戏,当游戏获胜时,我很难更改GIF动画。当JProgressBar等于0时,我更改了URL,但它什么也不做。如果有人可以帮助解决此问题,请提前感谢

  public class Player1 {

static JButton playerPunch = new JButton("Punch");
 static JButton playerKick = new JButton("Kick");
 static JButton playerSpecial = new JButton("Special Attack");
static JButton playerNothing = new JButton("Do Nothing");
public static void runAll(){
    PlayerPunch();
    PlayerKick();
    PlayerSpecial();
    PlayerNothing();
    endGame();

}
public static void endGame(){
    if(HealthBar.PlayerHealth.getValue() == 0){

    }
    if(HealthBar.EnemyHealth.getValue() == 0){
        Game.gifString = ("http://media.tumblr.com/tumblr_lgpely0wDJ1qg8wsi.gif");
    }
}
这里是另一个类的第二部分,包括URL本身

   static String gifString = new String("http://cdn.gifbay.com/2012/10/mortal_kombat_prom-3939.gif");
static JPanel playerPanel = new JPanel();
static JButton start = new JButton("Start");
static JButton exit = new JButton("Exit");
static JPanel menu = new Menu();
static JPanel bg = new JPanel();
static int state = 0;
public static void main(String[] args) throws MalformedURLException {

    JPanel buttonPane = new JPanel();
    final JPanel masterPanel = new JPanel(new BorderLayout());

    final JFrame f = new JFrame("Mortal Kombat Game");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
URL url = new URL(gifString);
Icon icon = new ImageIcon(url);
final JLabel label = new JLabel(icon);
final JLabel title = new JLabel("Mortal Kombat Game");
f.pack();

f.setVisible(true);
f.setSize(498,400);
f.setLocationRelativeTo(null);

1.你使用静电是错误的。2.仅仅切换一个URL对你没有多大帮助。3.从URL获取图像是一项长期运行的任务,不应该完成。而是在应用程序启动期间获取所需的所有图像,并将图像存储在以后可以访问的位置。然后用一个JLabel.setIcon或我看到的东西来切换它们,我要试试setIcon。你能给我解释一下,当我错误地使用静态变量时,你是什么意思吗?你需要了解实例变量和静态变量之间的区别,以及何时使用它们。所有组件都应该是实例组件,而不是静态组件。你可能觉得需要它们的唯一原因是因为1。您在main方法上做的太多了,它是静态的,并且要求访问的对象也是静态的2。你的其他方法也一样。这只意味着你的设计有问题。浏览一些课程设计的良好实践,我看到了,谢谢你的帮助,我将查看教程。事实上,我看到了问题所在。我添加了几行代码,在您丢失后在我的jbuttons上设置EnableFalse,但是它根本不会影响程序。我还更改了URL方法,并从计算机上的存储位置获取了GIF。