message dialog error
I get this error:
cannot find symbol
symbol: method showMessageDialog(<anonymous javax.swing.AbstractAction>,java.lang.String,java.lang.String,int)
Can someone help me? Thanks
exitAction = new
AbstractAction("Esci") {
public void actionPerformed(ActionEvent e) {
if (rcStatus ==1) {
开发者_JAVA百科 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");
There is no method in JOptionPane
with that signature. Are you sure that the this
you're passing in is an AbstractAction
, which is not a Component
. For showMessageDialog()
, these are your options.
I think you want JOptionPane.showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType)
. If you don't have a suitable parent component to pass in, pass null
instead of this
:
JOptionPane.showMessageDialog(null, "Thread running. Choose STOP before exit", "Error", JOptionPane.ERROR_MESSAGE);
In your method call, this
refers to the anonymous class that you are creating (that extends AbstractAction).
If this code is inside of a Component, such as:
public class MyComponent extends JComponent {
...
(your code)
then you can change your method call to:
JOptionPane.showMessageDialog(MyComponent.this, "Thread running", ...
MyComponent.this
refers to the outer class object.
精彩评论