123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.Panel;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- class AuthPanel extends Panel implements ActionListener {
- Label title, retry, prompt;
- TextField password;
- Button ok;
-
-
- Label promptuser;
- TextField username;
- boolean mslogon = false;
-
-
-
-
-
-
- public AuthPanel(boolean logon) {
- mslogon = logon;
-
-
- title = new Label("VNC Authentication",Label.CENTER);
- title.setFont(new Font("Helvetica", Font.BOLD, 18));
- prompt = new Label("Password:",Label.CENTER);
- password = new TextField(10);
- password.setForeground(Color.black);
- password.setBackground(Color.white);
- password.setEchoChar('*');
-
- if (mslogon) {
- promptuser = new Label("Username:",Label.CENTER);
- username = new TextField(10);
- username.setForeground(Color.black);
- username.setBackground(Color.white);
- }
-
-
- ok = new Button("OK");
- retry = new Label("",Label.CENTER);
- retry.setFont(new Font("Courier", Font.BOLD, 16));
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- setLayout(gridbag);
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(title,gbc);
- add(title);
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gridbag.setConstraints(retry,gbc);
- add(retry);
- gbc.fill = GridBagConstraints.NONE;
- gbc.gridwidth = 1;
-
-
-
- if (mslogon) {
- gridbag.setConstraints(promptuser,gbc);
- add(promptuser);
- gridbag.setConstraints(username,gbc);
- add(username);
- username.addActionListener(this);
- }
-
- gridbag.setConstraints(prompt,gbc);
- add(prompt);
- gridbag.setConstraints(password,gbc);
- add(password);
- password.addActionListener(this);
- gbc.ipady = 10;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.insets = new Insets(0,20,0,0);
- gbc.ipadx = 40;
- gridbag.setConstraints(ok,gbc);
- add(ok);
- ok.addActionListener(this);
- }
-
- public void setmslogon(boolean InfoMsLogon) {
- mslogon = InfoMsLogon;
- }
- public void moveFocusToUsernameField() {
- if (mslogon) { username.requestFocus(); }
- else { moveFocusToPasswordField();}
- }
-
-
-
-
-
-
- public void moveFocusToPasswordField() {
- password.requestFocus();
- }
-
-
-
-
- public synchronized void actionPerformed(ActionEvent evt) {
- if (evt.getSource() == password || evt.getSource() == ok) {
- password.setEnabled(false);
- notify();
- }
- }
-
-
-
- public void retry() {
- retry.setText("Sorry. Try again.");
- password.setEnabled(true);
- password.setText("");
- moveFocusToPasswordField();
- }
- }
|