以下代码有什么问题?

时间:2014-05-25 13:57:04

标签: java user-interface joptionpane

我希望在显示时将一个ImageIcon添加到JOptionPane,但是当我运行JOptionPane时,会显示但图标不显示...

注意:论证"这"是框架和圣托里尼是我制作的游戏,当游戏结束时,应该显示JOptionPane以宣布获胜者...所以任何帮助?

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

2 个答案:

答案 0 :(得分:0)

尝试使用这种方式..

ImageIcon icon = new ImageIcon(TestOptionPane04.class.getResource(path for image file));

JOptionPane.showMessageDialog(this,"Hello world","Hello", JOptionPane.INFORMATION_MESSAGE, icon);

答案 1 :(得分:0)

这对我有用。对于此示例,路径与java文件相同。

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