Search code examples
javauser-interfacejoptionpane

What is wrong this following code?


I wanted to add an ImageIcon to the JOptionPane when displayed but when i run the JOptionPane shows up but the icon does not ...

note : the argument "this" is the Frame and santorini is a game I made and the JOptionPane is supposed to be displayed when game is over to announce the winner ... so any help ?

if (santorini.isGameOver()) {
    JOptionPane.showMessageDialog(
        this, 
        "Winner is " + santorini.getWinner().getName(), 
        "Winner is",
        JOptionPane.INFORMATION_MESSAGE,
        new ImageIcon ("pyramid2nlayer 1.png")
    );
}

Solution

  • This is working for me. For this example path is same as java file.

        ImageIcon icon = new ImageIcon(getClass().getResource("image hello.jpg"));
        JOptionPane.showMessageDialog(this, "hi", "hello", JOptionPane.INFORMATION_MESSAGE, icon);