About JOption  Pane Class :

The JOptionPane class in Java is part of the javax.swing package and is used to create standard dialog boxes for user interaction in a graphical user interface (GUI). It provides a simple way to create dialogs for input, information, warnings, and error messages.

Here are some key features and methods of the JOptionPane class:

Key Features

  1. Message Dialogs: To display information or prompt the user with a message.
  2. Confirm Dialogs: To ask for user confirmation (Yes/No/Cancel).
  3. Input Dialogs: To prompt the user for a text input.
  4. Option Dialogs: To present a list of options for the user to choose from.

How to use (step one import class)

import javax.swing.JOptionPane;
//you can import this class like this

Moving to the methods / Functions of this class

1. simple popup / dialog box :
when you write JOptionPane then dot operator you will see lot of option 


 when you click on showMessageDialog :

you will see this code snipped


in this the args in the value which will be shown in dialog box and title is the name of that dialog box  and then there is message type it mean what type of this message should be like warning message emergency message or error message etc.

let's fill these value and see the output.

JOptionPane.showMessageDialog(null,
         "This is mccr learning",
         "My Box",
         JOptionPane.INFORMATION_MESSAGE);

you can see i added the args value "this is mccr learning 
and added title my box
and as message option the information option
let's see output



You can change this message type for different message type 

2. Input dialog box :

JOptionPane.showInputDialog(args);
here is simple code snipped when click on JOptionPane.showInputDialog(args)
and args you have to write message what type of input you want to get

some tips 
always in return string value
you can store string value to the created string varialbe
like this String name = .....code

Let us add values as args
JOptionPane.showInputDialog("what is your name");

let us see output of this

3.showConfirmDialog: Asks for confirmation from the user and returns an integer indicating the user's choice :

code snipped :



letus see Output :

key points
it return interger value
you can store that value in interger like this int option = code......
and if user click on yes it will reutrn 0 and if user click on no it will return 1 and if user click on cros icon or cut this it will return -1 .

4.showOptionDialog: Provides a custom set of options for the user to choose from:

Code snipped :
String[] options = {"Yes", "No", "I will"};
        JOptionPane.showOptionDialog(null,
        "Are You reading this on mccr learning site",
        "Option Dialog",
        JOptionPane.DEFAULT_OPTION,
        JOptionPane.INFORMATION_MESSAGE,
        null, options, options[0]);


in this code we created string options then class the show option dialog box 
and then added args and title and options 
and also you can add icon to this 

letus see output of this :

Key Points
it return interger value
it return 0 if first option clicked
it return 1 if 2nd option clicked
it return 2 if 3rd option clicked 
it return -1 if cross or exit button clicked 

If You want to get input of an other datatype you have to know parse concept

In Java, parsing is the process of converting a String into another data type, such as int, float, or double. This is often necessary when you're working with input data that comes in as a String, such as from user input or reading from a file, and you need to convert it to a numerical type for calculations or other operations.

Summary

  • Integer.parseInt(String s): Parses the string argument as a signed decimal integer.
  • Float.parseFloat(String s): Parses the string argument as a floating-point number.
  • Double.parseDouble(String s): Parses the string argument as a double-precision floating-point number.

Here's how you can parse different data types in JavaYou can customize the dialogs by providing additional parameters such as:

  • parentComponent: The parent component of the dialog (usually null if there's no parent).
  • message: The message to display.
  • title: The title of the dialog.
  • messageType: The type of message (e.g., JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE).
  • icon: A custom icon for the dialog.
  • options: An array of objects representing the options available to the user.
  • initialValue: The initially selected value.

The JOptionPane class is a versatile tool for creating dialogs in Java Swing applications, allowing for user interaction and input in a straightforward manner.

IT IS ALL FOR TODAY
Thanks for reading ....................