Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i display a message dialog box in java

Tags:

java

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

         }
      }  
like image 957
Developer Limit Avatar asked Oct 11 '25 19:10

Developer Limit


2 Answers

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


    }
}
like image 162
Developer Limit Avatar answered Oct 14 '25 08:10

Developer Limit


use this code

JOptionPane.showMessageDialog(null, "java is fun");
like image 24
MohammadReza Ghafarpour Avatar answered Oct 14 '25 08:10

MohammadReza Ghafarpour