[英]How do I make dialog windows in java?
I found a webpage on the java site on how to make dialog windows, but it isn't working when I try it. 我在Java网站上找到了一个有关如何制作对话框窗口的网页,但是当我尝试该网页时却无法正常工作。 The site said to type:
该网站说要输入:
JOptionPane.showMessageDialog(frame, "Window text.");
I'm just trying to make a window with a bit of text and an ok button, but when I type this in, my Eclipse IDE wants me to import something for the JOptionPane, and after I do that, it says the the "frame" part is incorrect, that it "cannot be resolved to a variable." 我只是想在窗口中放置一些文本和一个确定按钮,但是当我键入该窗口时,我的Eclipse IDE希望我为JOptionPane导入一些东西,然后我说,“框架”部分不正确,表示“无法解析为变量”。 What am I doing wrong here?
我在这里做错了什么?
Start by making sure you have included the import javax.swing.JOptionPane;
首先确保已包含
import javax.swing.JOptionPane;
statement within your import portion of your code. 您的代码导入部分中的语句。
Next, try using 接下来,尝试使用
JOptionPane.showMessageDialog(null, "Window text.");
instead. 代替。
For example... 例如...
import javax.swing.JOptionPane;
public class TestDialog {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Window text.");
}
}
Take a closer look at How to Make Dialogs for more details. 详细了解如何制作对话框 。
You should also consult the JavaDocs when in doubt... 如有疑问,还应查阅JavaDocs 。
The first parameter in the call to JOptionPane.showMessageDialog
should be an instance of a JFrame
or JWindow
that you want to assign your message dialog to. 调用
JOptionPane.showMessageDialog
的第一个参数应该是要将消息对话框分配给的JFrame
或JWindow
的实例。 If you don't have a JFrame
or JWindow
but still want to display the message dialog, just put in null
as the first parameter, like this: 如果您没有
JFrame
或JWindow
但仍想显示消息对话框,则只需将null
作为第一个参数,如下所示:
JOptionPane.showMessageDialog(null, "Window text.");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.