1

我正在学习 Java,但我不知道如何做到这一点。

我在 Netbeans 的表单上拖动了一个按钮,双击它并创建了这个事件:

@Action
public void HelloClickMethod() 
{
    JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title."); 
}

这是 IDE 提出的例外情况。

找不到标志。符号:showMessageDialog()

编辑 1> 现在我将其更改为:

@Action
public void HelloClickMethod()
{
    JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title.",JOptionPane.ERROR_MESSAGE);
}

但是 IDE 说我在“this”这个词中有一个错误。“找不到标志”。我不明白。为什么它如此困难,为什么错误如此深奥。:P

4

3 回答 3

5

我可以想到以下原因:您可能没有“导入”包含 JOptionPane 的包。尝试:

 import javax.swing.*;

在您的源文件之上。或者,使用

javax.swing.JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title.", JOptionPane.ERROR_MESSAGE);

提问者编辑后:

其他原因是方法的位置,如果您在静态上下文中,则不能使用this.

于 2010-01-16T05:00:28.237 回答
0

showMessageDialog 方法不带 3 个参数。试试这个:

  JOptionPane.showMessageDialog(this, "The message!", "This is supposed to be the MessageBox title.", JOptionPane.ERROR_MESSAGE);

有3个方法名为showMessageDialog,1个有2个参数(组件和消息),4个参数(组件,消息,标题,消息类型)和5个参数(组件,消息,标题,消息类型,图标)。

于 2010-01-16T04:53:53.463 回答
0

这工作正常:

JOptionPane.showMessageDialog(null,"ErrorMSG", "Title!", JOptionPane.WARNING_MESSAGE)
于 2014-04-09T11:22:37.477 回答