Code example for PasswordCallback

Methods: getPromptisEchoOnsetPassword

0
 
  protected synchronized void handlePassword(PasswordCallback c)
  { 
    Frame ownerFrame = new Frame();
    Dialog dialog = new Dialog(ownerFrame);
    dialog.setTitle(c.getPrompt());
    dialog.setLayout(new GridLayout(3, 1));
    Label label = new Label(c.getPrompt());
    TextField input = new TextField();
    if (!c.isEchoOn())
      { 
        input.setEchoChar('*');
      } 
    Panel buttons = new Panel();
    Button ok = new Button(messages.getString("callback.ok"));
    ok.setActionCommand(ACTION_OK);
    ok.addActionListener(this);
    Button cancel = new Button(messages.getString("callback.cancel"));
    cancel.setActionCommand(ACTION_CANCEL);
    cancel.addActionListener(this);
    dialog.add(label);
    dialog.add(input);
    buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
    buttons.add(ok);
    buttons.add(cancel);
    dialog.add(buttons);
    dialog.pack();
    dialog.show();
    try { wait(); }
    catch (InterruptedException ie) { }
    if (actionCommand.equals(ACTION_OK))
      { 
        c.setPassword(input.getText().toCharArray());
      } 
    dialog.dispose();
    ownerFrame.dispose();
  }