3

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"); 

         }
      }  
Developer Limit
  • 135
  • 1
  • 3
  • 9

2 Answers2

7

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);


    }
}
Developer Limit
  • 135
  • 1
  • 3
  • 9
4

use this code

JOptionPane.showMessageDialog(null, "java is fun");
YCF_L
  • 51,266
  • 13
  • 85
  • 129