You are here:   HomeJava ProgrammingSwingshowInputDialog Java Swing Example
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)

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);
         }
   }

showInputDialog Java Swing Example





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes 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.



What's New and Popular





Popular Article