Image Icon won't appear

44 views Asked by At

I am trying to add an Image Icon to my game so a logo appears when it is in the task bar. I get no errors when I run my code but the image won't appear.

public class Game implements Runnable {
    public static Game game = null;
    Thread GameThread = new Thread(this);
    GamePanel panel = new GamePanel(this);
    GameFrame frame = new GameFrame(panel);

    ImageIcon logo = new ImageIcon(getClass().getClassLoader().getResource("res/duckIcon.png")); //for image icon
public Game() {
        changeState(sceneNum);
        frame.add(panel);
        frame.pack();
        frame.setIconImage(logo.getImage());
        frame.setVisible(true);
    }

This is the GameFrame class:

public class GameFrame extends JFrame {

    GameFrame(GamePanel panel) {
        this.setSize(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("Duck World");
        this.setLocationRelativeTo(null);

I've tried implementing the IconImage in the GameFrame class to no avail. If anyone would like to look at the file structure, here is github link: https://github.com/stefancohn/DuckWorld

0

There are 0 answers