gpt4 book ai didi

java - JOptionPane 对话框错误

转载 作者:行者123 更新时间:2023-12-01 18:38:45 25 4
gpt4 key购买 nike

我收到此错误消息:

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);

最佳答案

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);

关于java - JOptionPane 对话框错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20774604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com