FileDocCategorySizeDatePackage
LogonDialog.javaAPI DocExample8456Sat Sep 12 03:01:00 BST 1998borland.samples.apps.chess.client

LogonDialog

public class LogonDialog extends Dialog implements OkCancelDialog, KeyListener
Displays the logon dialog & initiates the logon message to the server

Fields Summary
ResourceBundle
res
Panel
dlgPanel
Button
cancelButton
Button
okButton
Panel
client
Panel
buttonBar
FlowLayout
buttonBarFlowLayout
Panel
buttonBarGrid
GridLayout
buttonBarGridLayout
BorderLayout
logonBorderLayout
GridBagLayout
clientGridBagLayout
Label
statusLabel
Label
nameLabel
Label
passwordLabel
TextField
password
TextField
name
static String
pass
static String
login
boolean
loggingOn
ChessViewer
dlgParent
Constructors Summary
public LogonDialog(ChessViewer theParent)


      
    super(theParent.f,"",false);
    setTitle(res.getString("LOG_ON"));
    dlgParent = theParent;
    try {
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      dlgParent.statusLine.setText(res.getString("PLEASE_ENTER_YOUR"));
      jbInit();
      add(dlgPanel);
      dlgParent.setModal(true);
      Point y = dlgParent.listPanel.getLocation();
      Point x = dlgParent.ep.getLocation();
      pack();
      if (x.x <= 0) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = getPreferredSize();
        if (frameSize.height > screenSize.height)
          frameSize.height = screenSize.height;
        if (frameSize.width > screenSize.width)
          frameSize.width = screenSize.width;
        setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
      }
      else
        setLocation(x.x,y.y);
    }
    catch (Exception e) {
      String message = e.toString() ;
      e.printStackTrace();
    }
  
Methods Summary
public voidbadLogon()

    loggingOn = false;
  
public voidcancel(java.awt.event.ActionEvent evt)
CancelButtonListener invokes this OkCancelDialog interface method

    try {
      dispose();
      dlgParent.setModal(false);
      dlgParent.statusLine.setText(res.getString("FEEL_FREE_TO_USE_THE"));
      dlgParent.pDialog = null;
    }
    catch (Exception e) {
      String message = e.toString() ;
      //System.out.println("logonDlg err " + e + String.valueOf(i));
      e.printStackTrace();
    }
  
public voidgoodLogon()

    dispose();
    dlgParent.setModal(false);
    dlgParent.pDialog = null;
  
private voidjbInit()

    dlgPanel.setLayout(logonBorderLayout);

    buttonBar.setLayout(buttonBarFlowLayout);
    buttonBarGrid.setLayout(buttonBarGridLayout);
    buttonBarGridLayout.setColumns(2);
    buttonBarGridLayout.setHgap(6);
    okButton.setLabel(res.getString("LOG_ON"));
    okButton.addActionListener(new OkButtonListener(this));
    okButton.addKeyListener(this);
    buttonBarGrid.add(okButton );
    cancelButton.setLabel(res.getString("CANCEL"));
    cancelButton.addActionListener(new CancelButtonListener(this));
    cancelButton.addKeyListener(this);
    buttonBarGrid.add(cancelButton);
    buttonBar.add(buttonBarGrid);
    dlgPanel.add(buttonBar,BorderLayout.SOUTH);

    client.setLayout(clientGridBagLayout);
    statusLabel.setAlignment(Label.CENTER);
    statusLabel.setText(res.getString("WELCOME_TO_THE"));
    client.add(statusLabel,new GridBagConstraints2(0, 0, 2, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    nameLabel.setText(res.getString("YOUR_NAME"));
    client.add(nameLabel,new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 20, 4, 0), 0, 0));
    name.setText(login);
    name.addKeyListener(this);
    name.selectAll();
    client.add(name,new GridBagConstraints2(1, 1, 1, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20), 20, 0));

    passwordLabel.setText(res.getString("PASSWORD"));
    client.add(passwordLabel,new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 20, 4, 0), 0, 0));
    password.setText(pass);
    password.addKeyListener(this);
    password.selectAll();
    password.setEchoChar('*");     //NORES
    client.add(password,new GridBagConstraints2(1, 2, 1, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20), 20, 0));
    dlgPanel.add(client,BorderLayout.CENTER);
  
public voidkeyPressed(java.awt.event.KeyEvent parm1)

    //TODO: implement this  java.awt.event.KeyListener method;
  
public voidkeyReleased(java.awt.event.KeyEvent e)

    if (e.getKeyCode() == KeyEvent.VK_ENTER)
       if (e.getSource() == cancelButton)
         cancel(null);
       else
         ok(null);
     else
     if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
        cancel(null);
  
public voidkeyTyped(java.awt.event.KeyEvent parm1)

    //TODO: implement this  java.awt.event.KeyListener method;
  
public voidok(java.awt.event.ActionEvent evt)
OkButtonListener invokes this OkCancelDialog interface method

    if (!loggingOn) {
    try {
      loggingOn = true;
      login = name.getText();
      if (login != null)
        login = login.trim();
      dlgParent.myName  = login;
      pass = password.getText() ;
      if (pass != null)
        pass = pass.trim();
      if (login == null ) {
        name.requestFocus();
        statusLabel.setText(res.getString("INEED_A_NAME"));
        loggingOn = false;
        return ;
      }
      if (login.length() < 2)   {
        statusLabel.setText(res.getString("PLEASE_CHOOSE_A"));
        name.requestFocus();
        name.selectAll();
        loggingOn = false;
        return ;
      }
      if (pass == null  || pass.indexOf('[") != -1 ) {
        password.requestFocus();
        statusLabel.setText(res.getString("INEED_A_PASSWORD"));
        pass = "";
        loggingOn = false;
        return ;
      }
      if (pass.length() < 2)   {
        statusLabel.setText(res.getString("PLEASE_CHOOSE_PASSWORD"));
        password.requestFocus();
        password.selectAll();
        loggingOn = false;
        return;
      }
      dlgParent.statusLine.setText(res.getString("LOGGING_ON_"));
      dlgParent.sendMsg("Name",login + "[" + pass) ;
      password.requestFocus();
    }
    catch (Exception e) {
      String message = e.toString() ;
      //System.out.println("logonDlg err " + e + String.valueOf(i));
      e.printStackTrace();
    }
    }
  
protected voidprocessWindowEvent(java.awt.event.WindowEvent e)
Dispose dialog if system close is activated .


    if (e.getID() == WindowEvent.WINDOW_CLOSING)
      cancel(null);
    else
      super.processWindowEvent(e);
  
public voidsetVisible(boolean isVisible)

    super.setVisible(isVisible);
    if (isVisible)
      if (login != null && login.length() > 0)
        okButton.requestFocus();
      else
        name.requestFocus();