将.gif添加到图形组件?

时间:2015-12-03 20:49:57

标签: java

我这里有一点问题。 我和一群朋友创造了一些扫雷并且需要创建一个动画来放置一个"炸弹"当它被点击并激活但没有任何反应。这是从高度投票的堆栈溢出帖子中获取的轻微代码,但它在某种程度上不起作用。问候。

package game;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class Mine extends Tile {

public Mine(boolean isMine, boolean isHidden) {
    // Always set hidden to false as Mine is a visible tile.
    // Always set mine to true as Mine is a mine.
    super(true, false);
}

public void render(Graphics g, int x, int y) {

    g.setColor(Color.RED);
     Image icon = null;
    try {
        icon = new ImageIcon(new URL("http://i.stack.imgur.com/KSnus.gif")).getImage();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

      g.drawImage(icon, 0, 0, 50, 50, this);


}

0 个答案:

没有答案