Developer Limit
Developer Limit

Reputation: 175

how can i display a message dialog box in 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"); 

         }
      }  

Upvotes: 4

Views: 41343

Answers (2)

Developer Limit
Developer Limit

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

use this code

JOptionPane.showMessageDialog(null, "java is fun");

Upvotes: 4

Related Questions