繁体   English   中英

在对话框上

[英]On dialog boxes

我正在尝试制作一个显示答案的对话框,并将其打印到屏幕上,但没有成功。 代码如下:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dialogbox;
import javax.swing.JOptionPane;
/**
 *
 * @author Tyranax87
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String name = "";
        //Setting up a variable name of type string and initialising it to the empty string.
        name = JOptionPane.showInputDialog(null, "Please input your name");
        System.exit(0);
}
}

它将运行得很好,但是只会弹出询问该问题的对话框。 有没有办法让对话框显示代码中的预写文本?

像这样尝试:

name = (String)JOptionPane.showInputDialog(
                    null,
                    "Please input your name",
                    "Title of the window",
                    JOptionPane.PLAIN_MESSAGE,
                    icon,
                    null,
                    "default text");

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM