public static String response(final String cQuestion,final String cTitle,final String cDefault,final boolean bPassword,final String cLabel){
  final BorderLayout layout=new BorderLayout();
  layout.setHgap(5);
  final JPanel panel=new JPanel(layout);
  final JLabel question=new JLabel(cQuestion);
  final JTextField field;
  if (bPassword) {
    field=new JPasswordField();
  }
 else {
    field=new JTextField();
  }
  if (cDefault != null) {
    field.setText(cDefault);
  }
  final String title;
  if (cTitle != null) {
    title=cTitle;
  }
 else {
    title="Input";
  }
  panel.add(question,BorderLayout.NORTH);
  if (cLabel != null) {
    final JLabel label=new JLabel(cLabel);
    panel.add(label,BorderLayout.WEST);
  }
  panel.add(field,BorderLayout.CENTER);
  final String[] options={"Ok","Cancel"};
  final int option=JOptionPane.showOptionDialog(null,panel,title,JOptionPane.NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,options,options[0]);
  if (option == 0) {
    return field.getText();
  }
 else {
    return null;
  }
}

public static String response ( final String cQuestion , final String cTitle , final String cDefault , final boolean bPassword , final String cLabel ) { final BorderLayout layout = new BorderLayout ( ) ; layout . setHgap ( 5 ) ; final JPanel panel = new JPanel ( layout ) ; final JLabel question = new JLabel ( cQuestion ) ; final JTextField field ; if ( bPassword ) { field = new JPasswordField ( ) ; } else { field = new JTextField ( ) ; } if ( cDefault != null ) { field . setText ( cDefault ) ; } final String title ; if ( cTitle != null ) { title = cTitle ; } else { title = "Input" ; } panel . add ( question , BorderLayout . NORTH ) ; if ( cLabel != null ) { final JLabel label = new JLabel ( cLabel ) ; panel . add ( label , BorderLayout . WEST ) ; } panel . add ( field , BorderLayout . CENTER ) ; final String [ ] options = { "Ok" , "Cancel" } ; final int option = JOptionPane . showOptionDialog ( null , panel , title , JOptionPane . NO_OPTION , JOptionPane . PLAIN_MESSAGE , null , options , options [ 0 ] ) ; if ( option == 0 ) { return field . getText ( ) ; } else { return null ; } }
displays a dialog box containing a question and an entry field for the user to reply to the question .
