2 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
3 // Copyright (C) 2002-2006 Constantin Kaplinsky. All Rights Reserved.
5 // This is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This software is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this software; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 import java.awt.event.*;
25 // The panel which implements the user authentication scheme
28 class AuthPanel extends Panel implements ActionListener {
30 TextField passwordField;
37 public AuthPanel(VncViewer viewer)
39 Label titleLabel = new Label("VNC Authentication", Label.CENTER);
40 titleLabel.setFont(new Font("Helvetica", Font.BOLD, 18));
42 Label promptLabel = new Label("Password:", Label.CENTER);
44 passwordField = new TextField(10);
45 passwordField.setForeground(Color.black);
46 passwordField.setBackground(Color.white);
47 passwordField.setEchoChar('*');
49 okButton = new Button("OK");
51 GridBagLayout gridbag = new GridBagLayout();
52 GridBagConstraints gbc = new GridBagConstraints();
56 gbc.gridwidth = GridBagConstraints.REMAINDER;
57 gbc.insets = new Insets(0,0,20,0);
58 gridbag.setConstraints(titleLabel,gbc);
61 gbc.fill = GridBagConstraints.NONE;
63 gbc.insets = new Insets(0,0,0,0);
64 gridbag.setConstraints(promptLabel,gbc);
67 gridbag.setConstraints(passwordField,gbc);
69 passwordField.addActionListener(this);
72 gbc.gridwidth = GridBagConstraints.REMAINDER;
73 gbc.fill = GridBagConstraints.BOTH;
74 gbc.insets = new Insets(0,20,0,0);
76 gridbag.setConstraints(okButton,gbc);
78 okButton.addActionListener(this);
82 // Move keyboard focus to the default object, that is, the password
86 public void moveFocusToDefaultField()
88 passwordField.requestFocus();
92 // This method is called when a button is pressed or return is
93 // pressed in the password text field.
96 public synchronized void actionPerformed(ActionEvent evt)
98 if (evt.getSource() == passwordField || evt.getSource() == okButton) {
99 passwordField.setEnabled(false);
105 // Wait for user entering a password, and return it as String.
108 public synchronized String getPassword() throws Exception
112 } catch (InterruptedException e) { }
113 return passwordField.getText();