我收到此错误消息:
The method showMessageDialog(Component, Object, String, int, Icon) in the type
JOptionPane is not applicable for the arguments (JFrame, String, String, int, int, ImageIcon, String)
当我将鼠标悬停在JOptionPane.showMessageDialog上时。我按照java教程,不知道是什么问题。有什么想法吗?
Java教程:http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#button
String option = "Restart";
JFrame frame = new JFrame();
ImageIcon ic = new ImageIcon("hangmanIcon.png");
JOptionPane.showMessageDialog(frame,
"He's dead, game over. The word was " + wordList[level],
"You Lost",
JOptionPane.OK_OPTION,
JOptionPane.INFORMATION_MESSAGE,
ic,
option);
答案 0 :(得分:4)
Java API for JOptionPane将告诉您签名可用/允许的方法,并且该方法签名不是一个。你可能想要使用这个:
public static void showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType,
Icon icon)
throws HeadlessException
修改
也许您想要使用的不是showMessageDialog
,而是允许更多参数的showOptionDialog
。
String[] options = {"Restart", "Exit"};
String option = options[0];
JFrame frame = new JFrame();
ImageIcon ic = new ImageIcon("hangmanIcon.png");
JOptionPane.showMessageDialog(frame,
"He's dead, game over. The word was " + wordList[level],
"You Lost",
JOptionPane.OK_OPTION,
JOptionPane.INFORMATION_MESSAGE,
ic,
options,
option);