Entering Text in a Dialog Figure 3.13 uses another predefined JOptionPane dialog called an input dialog that allows the user to enter data into a program. The program asks for the user’s name and responds with a message dialog containing a greeting and the name that the user entered.
How to create an Input Dialog Box In Java
/*
* Filename: NameDialog.java
*
* Description: 3.18 - Basic input with a dialog box
*
* @Author: Bilal Tahir Khan Meo
* Website: https://codeblah.com
*
* =====================================================================================
*/
import javax.swing.JOptionPane;
public class NameDialog{
public static void main(String[] args){
// prompt for name
String name = JOptionPane.showInputDialog("What is your name? ");
// create the message
String message = String.format("Welcome, %s to Java Programming!", name);
// show message
JOptionPane.showMessageDialog(null, message);
}
}