在Java中显示弹出消息窗口?

How*_*can 2 java swing jdialog joptionpane

我读到了JDialogs和JOptionPane消息,但我仍然无法让它工作.我有一个扩展JFrame的GUI类.我想要做的就是在程序开头弹出一个弹出窗口,告诉用户一些事情.在我的主要内容中,我创建了以下gui:

GUI g = new GUI();
Run Code Online (Sandbox Code Playgroud)

在那之后我就是要显示窗口.我在main方法中尝试了以下内容:

JOptionPane.showMessageDialog(g, "work?");
JOptionPane.showMessageDialog(frame, "work?"); //(frame was used in documentation example so I tried it)
Run Code Online (Sandbox Code Playgroud)

我还尝试使用以下内容将弹出窗口添加到GUI类中

JOptionPane.showMessageDialog(this, "work?"); //(I'm not exactly sure what the Frame Owner parameter is supposed to be, unless I'm confusing this with JDialog.)
Run Code Online (Sandbox Code Playgroud)

在任何情况下,我将如何使这个窗口出现?我尝试编译的每一个方法都没有发生.

public class GUI extends JFrame implements ActionListener{
     private Container background;
     private static buttons etc...
     private static JLabel disp,edisp;
     private static JTextArea info;
     //setting up the GUI for my program, adding action listeners, I can post more if    necessary
}
Run Code Online (Sandbox Code Playgroud)

然后我有主要的地方我想调用弹出窗口

public static void main(String[] args){
    GUI g = new GUI();
    JOptionPane.showMessageDialog(g,"Work?");
}
Run Code Online (Sandbox Code Playgroud)

Ota*_*nan 5

确保在开头附近调用它们,无论是否在main方法中.另外,尝试将第一个参数设置为null.所以它写道:

JOptionPane.showMessageDialog(null,"Work?");
Run Code Online (Sandbox Code Playgroud)

另外,记得导入它!