I read about JDialogs and JOptionPane messages but I still can't get it to work. I have a GUI class that extends JFrame. All I want to do is have a popup at the beginning of my program which informs the user about a couple of things. In my main I create the following gui:
我读过JDialogs和JOptionPane的消息,但我仍然不能让它工作。我有一个扩展JFrame的GUI类。我要做的就是在程序开始时弹出一个弹出窗口,告诉用户一些事情。在我的main中,我创建了以下gui:
GUI g = new GUI();
Right after that I was to display the window. I have tried the following in the main method:
就在那之后,我要把窗户打开。我尝试了以下主要方法:
JOptionPane.showMessageDialog(g, "work?");
JOptionPane.showMessageDialog(frame, "work?"); //(frame was used in documentation example so I tried it)
I also tried to add the pop up into the GUI class with the following
我还尝试在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.)
In any case, how would I make this window appear? Every single one of the methods I tried compiled, and nothing happened.
无论如何,我如何使这个窗口出现?我试过的每一种方法都是经过编译的,什么都没有发生。
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
}
And then I have the main where I want to call the pop up window
然后我有一个主要的地方,我想叫它弹出窗口。
public static void main(String[] args){
GUI g = new GUI();
JOptionPane.showMessageDialog(g,"Work?");
}
1 个解决方案
#1
5
Make sure that these are called near the beginning, be it in the main method or not. Also, try just setting the first parameter as null. So it reads:
请确保这些都是在开始时调用的,无论在主方法中还是在主方法中。另外,尝试将第一个参数设置为null。它写着:
JOptionPane.showMessageDialog(null,"Work?");
Also, remember to import it!
另外,记住要导入它!
#1
5
Make sure that these are called near the beginning, be it in the main method or not. Also, try just setting the first parameter as null. So it reads:
请确保这些都是在开始时调用的,无论在主方法中还是在主方法中。另外,尝试将第一个参数设置为null。它写着:
JOptionPane.showMessageDialog(null,"Work?");
Also, remember to import it!
另外,记住要导入它!