33 - Input Using Swing Input-Dialog in Java - By eZeon

Опубликовано: 10 Октябрь 2024
на канале: Vikram Thakur
1,664
10

Java Swing API(javax.swing) has JOptionPane class contains simple static method for different purpose. The method JOptionPane.showInputDialog() is used to take single line input from a small dialog box.

Sample Code:
import javax.swing.JOptionPane;
/**
Taking input using GUI input-dialog (Swing)
@author Vikram
*/
public class TakeGUIInput {
public static void main(String[] args) {
String name = JOptionPane.showInputDialog("Your Name: ");

String strSal = JOptionPane.showInputDialog("Enter Salary:");
Float salary = new Float(strSal);

Integer age = new Integer(JOptionPane.showInputDialog("Enter Age: "));

System.out.println("Name: "+name);
System.out.println("Salary: "+salary);
System.out.println("Age: "+age);
}
}