为什么这个JOptionPane命令不起作用?

时间:2017-05-25 05:56:48

标签: java

为什么这个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)

2 个答案:

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