Reputation: 175
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
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");
}
}
Upvotes: 4
Views: 41343
Reputation: 175
use JOptionPane.showMessageDialog()
method and you can define some or all the arguments of the method
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);
}
}
Upvotes: 10
Reputation: 59
use this code
JOptionPane.showMessageDialog(null, "java is fun");
Upvotes: 4