by Dinesh Thakur Category: Swing

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)


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());
        public void actionPerformed(ActionEvent e1)
           String Rslt = JOptionPane.showInputDialog(Msg);
           if(Rslt == null)
           showStatus("You Pressed Cancel");
           showStatus("You typed : " + Rslt);

showInputDialog Java Swing Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles