我正在尝试制作一个对话框,它显示答案并将打印到屏幕上,但没有成功。代码如下所示:
/*
* 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");
关于java - 在对话框上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1506273/