FileDocCategorySizeDatePackage
DialogAuthenticator.javaAPI DocExample3276Sat Sep 09 19:54:08 BST 2000com.macfaq.net

DialogAuthenticator

public class DialogAuthenticator extends Authenticator

Fields Summary
private JDialog
passwordDialog
private JLabel
mainLabel
private JLabel
userLabel
private JLabel
passwordLabel
private JTextField
usernameField
private JPasswordField
passwordField
private JButton
okButton
private JButton
cancelButton
PasswordAuthentication
response
Constructors Summary
public DialogAuthenticator()

  
    
    this("", new JFrame());
  
public DialogAuthenticator(String username)

    this(username, new JFrame());
  
public DialogAuthenticator(JFrame parent)

    this("", parent);
  
public DialogAuthenticator(String username, JFrame parent)

    
    this.passwordDialog = new JDialog(parent, true);  
    Container pane = passwordDialog.getContentPane();
    pane.setLayout(new GridLayout(4, 1));
    pane.add(mainLabel);
    JPanel p2 = new JPanel();
    p2.add(userLabel);
    p2.add(usernameField);
    usernameField.setText(username);
    pane.add(p2);
    JPanel p3 = new JPanel();
    p3.add(passwordLabel);
    p3.add(passwordField);
    pane.add(p3);
    JPanel p4 = new JPanel();
    p4.add(okButton);
    p4.add(cancelButton);
    pane.add(p4);   
    passwordDialog.pack();
    
    ActionListener al = new OKResponse();
    okButton.addActionListener(al);
    usernameField.addActionListener(al);
    passwordField.addActionListener(al);
    cancelButton.addActionListener(new CancelResponse());
    
  
Methods Summary
public java.net.PasswordAuthenticationgetPasswordAuthentication()

    
    this.show();    
    return this.response;
    
  
private voidshow()

    
    String prompt = this.getRequestingPrompt();
    if (prompt == null) {
      String site     = this.getRequestingSite().getHostName();
      String protocol = this.getRequestingProtocol();
      int    port     = this.getRequestingPort();
      if (site != null & protocol != null) {
        prompt = protocol + "://" + site;
        if (port > 0) prompt += ":" + port;
      }
      else {
        prompt = ""; 
      }
      
    }

    mainLabel.setText("Please enter username and password for "
     + prompt + ": ");
    passwordDialog.pack();
    passwordDialog.show();