2011-01-12 120 views
0

我得到這個錯誤:消息對話框錯誤

cannot find symbol 
symbol: method showMessageDialog(<anonymous javax.swing.AbstractAction>,java.lang.String,java.lang.String,int) 

有人能幫助我嗎? 感謝

exitAction = new 
AbstractAction("Esci") { 

      public void actionPerformed(ActionEvent e) { 

      if (rcStatus ==1) { 

    JOptionPane.showMessageDialog(this, 
"Thread running. Choose STOP before 
exit", 
        "Error", JOptionPane.ERROR_MESSAGE); 


     } 
      else { 

       System.exit(0);} 

      } 
     }; 
     exitAction.putValue(Action.NAME, 
     "Exit"); 

     exitAction.putValue(Action.SHORT_DESCRIPTION,"Close"); 

回答

0

在你的方法調用,this指的是要創建匿名類(擴展AbstractAction)。

如果此代碼是一個組件內,如:

public class MyComponent extends JComponent { 
... 
(your code) 

那麼您可以在方法調用更改爲:

JOptionPane.showMessageDialog(MyComponent.this, "Thread running", ... 

MyComponent.this指外部類對象。

+0

它是private void createActions(){......}的一部分我應該重寫整個代碼嗎?謝謝 – max 2011-01-12 15:39:36