java 我如何在java中显示消息对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42725666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can i display a message dialog box in java
提问by Developer Limit
i want to display a message dialog box in java. At this moment i can only display a message in a console by using System.out.println()
method
我想在java中显示一个消息对话框。目前我只能通过使用System.out.println()
方法在控制台中显示一条消息
Example :
例子 :
public class demo{
public static void main(String[] x){
// i want to display the below message in a dialog box
System.out.print("java is fun");
}
}
回答by MohammadReza Ghafarpour
use this code
使用此代码
JOptionPane.showMessageDialog(null, "java is fun");
回答by Developer Limit
use JOptionPane.showMessageDialog()
method and you can define some or all the arguments of the method
使用JOptionPane.showMessageDialog()
方法,您可以定义方法的部分或全部参数
Code example :
代码示例:
import javax.swing.JOptionPane; // import javax packages
public class demo {
public static void main(String[] args){
// using showMessageDialog(component parentComponent,String message,String messageTitle,int optionType) method to display a message dialog box
JOptionPane.showMessageDialog(null,"java is fun","Title",1);
}
}