An input dialog box is used to accept data from the user. It appears with a component like text field, combo box or list which lets the user to input the data. It is created by using the static method
showinputDialog () of JOptionPane.The general form of showinputDialog () method is
public static String showinputDialog(Component parentComponent,Object message)
where,
parentComponent is the parent component of the dialog
message is the message to be displayed
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/*<APPLET CODE =JavaExampleDialogTextInJApplet.class WIDTH = 350 HEIGHT = 280> </APPLET>*/
public class JavaExampleDialogTextInJApplet extends JApplet implements ActionListener
{
JButton BtnShw = new JButton("Show Dialog");
String Msg = "Enter the Words";
public void init()
{
Container Cntnr = getContentPane();
Cntnr.setLayout(new FlowLayout());
Cntnr.add(BtnShw);
BtnShw.addActionListener(this);
}
public void actionPerformed(ActionEvent e1)
{
String Rslt = JOptionPane.showInputDialog(Msg);
if(Rslt == null)
showStatus("You Pressed Cancel");
else
showStatus("You typed : " + Rslt);
}
}