An input dialog box asks a question and uses a text field to store the response.

The easiest way to create an input dialog in Java is to use showInputDialog(Component, Object, String, int) method of JOptionPane class.

The following example uses this method to create an input dialog box:

 String response = JOptionPane.showInputDialog(null,
  "What is your name?",
  "Enter your name",
  JOptionPane.QUESTION_MESSAGE);