Academic Java    Java Tutorial  >  Swing  >  JOptionPane - input

JOptionPane - input Example

Java JOptionPane - input EXAMPLE output Java JOptionPane - input EXAMPLE output The Input dialog type is called from the method showInputDialog() which asks the user to enter a string.

An initValue can be supplied as a default response for the user to accept or edit as appropriate.
// JOptionPane showInputDialog() Example
import javax.swing.*;

class JOptionPaneExample3 {

   static String show(String message, Object initValue) {
      String reply = null;

      if(initValue==null) reply=JOptionPane.showInputDialog(message);
      else reply=JOptionPane.showInputDialog(message, initValue);

      return reply;
   }


   public static void main(String[] args) {
      String s="";

      s = show("Enter your last name", null);
      System.out.println("name = " + s);

      s = show("Is it after mid-day where you are?", "yes");
      System.out.println("after mid-day? " + s);
   }

}


* JOptionPane Examples