2017-05-25 114 views
0

這個JOptionPane命令爲什麼不起作用?爲什麼這個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

您試圖通過傳遞錯誤參數來調用方法。沒有像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); 
0

你忘了title說法。它應該在消息後立即進行傳遞:

JOptionPane.showMessageDialog (null, 
           "Wrong character entered.", 
           "Title", 
           JOptionPane.ERROR_MESSAGE); 

有關此方法的詳細信息:訪問here