简体   繁体   English

如何在Java中创建对话框窗口?

[英]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的第一个参数应该是要将消息对话框分配给的JFrameJWindow的实例。 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: 如果您没有JFrameJWindow但仍想显示消息对话框,则只需将null作为第一个参数,如下所示:

JOptionPane.showMessageDialog(null, "Window text.");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使警报对话框在Java中按位置按字符串显示项目? - How do I make an alert dialog display items in a string by position in Java? Java Swing-如何使关闭对话框不会关闭整个程序? - Java Swing - How do I make it so that closing a Dialog box doesn't close the entire program? 如何在Swing中制作动态窗口? - How do I make dynamic windows in Swing? 如何制作自定义Windows服务? - How do I make a custom windows service? 如何使我的底部工作表对话框动态化? - How do I make my Bottom Sheet Dialog dynamic? 如何使对话框片段的背景不可见? - How do I make a Dialog Fragment's background invisible? 如何在Java中创建一个允许主应用程序完全退出的后台线程?这适用于Linux,但不适用于Windows - How do I make a background thread in Java that allows the main application to exit completely? This works in Linux, but not in Windows 如何使Windows XP计算机停止尝试使用已卸载的Java JDK(1.6.0_13) - How do I make Windows XP machine stop trying to use uninstalled Java JDK (1.6.0_13) 如何使用 Windows 8.1 使命令 java -version 在我的计算机上工作? - How do I make the command java -version work on my computer with Windows 8.1? 如何在 Java 中执行 Windows 命令? - How do I execute Windows commands in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM