I'm getting this error message:
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)
When I hover over JOptionPane.showMessageDialog. I followed the java tutorial and don't know what the problem is. Any idea?
Java tutorial: 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);
The Java API for JOptionPane will tell you what method signatures are available/allowed, and that method signature isn't one. You probably want to use this one instead:
public static void showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType,
Icon icon)
throws HeadlessException
Edit
Perhaps what you want to use instead is not the showMessageDialog
but rather the showOptionDialog
which does allow for more parameters.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.