为什么这个JOptionPane命令不起作用?
if (let != 'D' || let != 'S' || let != 'M' || let != 'A' || let != 'X'){
JOptionPane.showMessageDialog (null, "Wrong character entered.",
JOptionPane.ERROR_MESSAGE);}
它似乎给了我错误信息:
JOptionPane.showMessageDialog (null, "Wrong character entered.", JOptionPane.ERROR_MESSAGE);}
^
method JOptionPane.showMessageDialog(Component,Object,String,int,Icon) is not applicable (actual and formal argument lists differ in length)
method JOptionPane.showMessageDialog(Component,Object,String,int) is not applicable (actual and formal argument lists differ in length)
method JOptionPane.showMessageDialog(Component,Object) is not applicable (actual and formal argument lists differ in length)
答案 0 :(得分:0)
您忘记了title
参数。它应该在消息后立即传递:
JOptionPane.showMessageDialog (null,
"Wrong character entered.",
"Title",
JOptionPane.ERROR_MESSAGE);
有关此方法的详情,请访问here。
答案 1 :(得分:0)
您试图通过传递错误的参数来调用方法。没有像JOptionPane.showMessageDialog(Component parentComponent,String message,int messageType
)这样的方法。
可能你正在寻找这种方法。 JOptionPane#showMessageDialog(Component parentComponent, Object message, String title, int messageType)
。
您可以将String
作为DialogBox
的标题传递。
所以改变
JOptionPane.showMessageDialog (null, "Wrong character entered.", JOptionPane.ERROR_MESSAGE);
到
JOptionPane.showMessageDialog (null, "Wrong character entered.", "Attention!" ,JOptionPane.ERROR_MESSAGE);