35
32
System.out.println("");
38
String host=JOptionPane.showInputDialog("Enter username@hostname",
39
System.getProperty("user.name")+
40
host=JOptionPane.showInputDialog("Enter username@hostname",
41
System.getProperty("user.name")+
41
44
String user=host.substring(0, host.indexOf('@'));
42
45
host=host.substring(host.indexOf('@')+1);
72
public static class MyUserInfo implements UserInfo{
80
public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{
73
81
public String getPassword(){ return passwd; }
74
82
public boolean promptYesNo(String str){
75
83
Object[] options={ "yes", "no" };
101
109
public void showMessage(String message){
102
110
JOptionPane.showMessageDialog(null, message);
112
final GridBagConstraints gbc =
113
new GridBagConstraints(0,0,1,1,1,1,
114
GridBagConstraints.NORTHWEST,
115
GridBagConstraints.NONE,
116
new Insets(0,0,0,0),0,0);
117
private Container panel;
118
public String[] promptKeyboardInteractive(String destination,
123
panel = new JPanel();
124
panel.setLayout(new GridBagLayout());
127
gbc.gridwidth = GridBagConstraints.REMAINDER;
129
panel.add(new JLabel(instruction), gbc);
132
gbc.gridwidth = GridBagConstraints.RELATIVE;
134
JTextField[] texts=new JTextField[prompt.length];
135
for(int i=0; i<prompt.length; i++){
136
gbc.fill = GridBagConstraints.NONE;
139
panel.add(new JLabel(prompt[i]),gbc);
142
gbc.fill = GridBagConstraints.HORIZONTAL;
145
texts[i]=new JTextField(20);
148
texts[i]=new JPasswordField(20);
150
panel.add(texts[i], gbc);
154
if(JOptionPane.showConfirmDialog(null, panel,
155
destination+": "+name,
156
JOptionPane.OK_CANCEL_OPTION,
157
JOptionPane.QUESTION_MESSAGE)
158
==JOptionPane.OK_OPTION){
159
String[] response=new String[prompt.length];
160
for(int i=0; i<prompt.length; i++){
161
response[i]=texts[i].getText();
166
return null; // cancel