comparison src/treeVnc/AuthPanel.java @ 0:756bfaf731f3

create new repository
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Tue, 21 Feb 2012 04:10:12 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:756bfaf731f3
1 package treeVnc;
2 //
3 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
4 // Copyright (C) 2002-2006 Constantin Kaplinsky. All Rights Reserved.
5 //
6 // This is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This software is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this software; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20 //
21
22 import java.awt.*;
23 import java.awt.event.*;
24
25 //
26 // The panel which implements the user authentication scheme
27 //
28
29 class AuthPanel extends Panel implements ActionListener {
30
31 /**
32 *
33 */
34 private static final long serialVersionUID = 1L;
35 TextField passwordField;
36 Button okButton;
37
38 //
39 // Constructor.
40 //
41
42 public AuthPanel(VncViewer viewer)
43 {
44 Label titleLabel = new Label("VNC Authentication", Label.CENTER);
45 titleLabel.setFont(new Font("Helvetica", Font.BOLD, 18));
46
47 Label promptLabel = new Label("Password:", Label.CENTER);
48
49 passwordField = new TextField(10);
50 passwordField.setForeground(Color.black);
51 passwordField.setBackground(Color.white);
52 passwordField.setEchoChar('*');
53
54 okButton = new Button("OK");
55
56 GridBagLayout gridbag = new GridBagLayout();
57 GridBagConstraints gbc = new GridBagConstraints();
58
59 setLayout(gridbag);
60
61 gbc.gridwidth = GridBagConstraints.REMAINDER;
62 gbc.insets = new Insets(0,0,20,0);
63 gridbag.setConstraints(titleLabel,gbc);
64 add(titleLabel);
65
66 gbc.fill = GridBagConstraints.NONE;
67 gbc.gridwidth = 1;
68 gbc.insets = new Insets(0,0,0,0);
69 gridbag.setConstraints(promptLabel,gbc);
70 add(promptLabel);
71
72 gridbag.setConstraints(passwordField,gbc);
73 add(passwordField);
74 passwordField.addActionListener(this);
75
76 // gbc.ipady = 10;
77 gbc.gridwidth = GridBagConstraints.REMAINDER;
78 gbc.fill = GridBagConstraints.BOTH;
79 gbc.insets = new Insets(0,20,0,0);
80 gbc.ipadx = 30;
81 gridbag.setConstraints(okButton,gbc);
82 add(okButton);
83 okButton.addActionListener(this);
84 }
85
86 //
87 // Move keyboard focus to the default object, that is, the password
88 // text field.
89 //
90
91 public void moveFocusToDefaultField()
92 {
93 passwordField.requestFocus();
94 }
95
96 //
97 // This method is called when a button is pressed or return is
98 // pressed in the password text field.
99 //
100
101 public synchronized void actionPerformed(ActionEvent evt)
102 {
103 if (evt.getSource() == passwordField || evt.getSource() == okButton) {
104 passwordField.setEnabled(false);
105 notify();
106 }
107 }
108
109 //
110 // Wait for user entering a password, and return it as String.
111 //
112
113 public synchronized String getPassword() throws Exception
114 {
115 try {
116 wait();
117 } catch (InterruptedException e) { }
118 return passwordField.getText();
119 }
120
121 }