Monday, March 10, 2008

 

Simple Swing Login Form

下面這段code會產生出上面那樣的小Dialog視窗讓你輸入帳號密碼進行登入
是最近玩JAAS時寫的
不過其實在JAAS裡面有更方便讓人拿來用的東西
那就是javax.security.auth.callback package與com.sun.security.auth.callback package裡面的東東
怎麼用的話...有機會再跟大家說


JPanel panel = new JPanel(new GridLayout(2, 2));
JTextField nameField = new JTextField();
JPasswordField passwordField = new JPasswordField();
panel.add(new JLabel("ID"));
panel.add(nameField);
panel.add(new JLabel("Password"));
panel.add(passwordField);
while (JOptionPane.showConfirmDialog(null, panel, "Please Login",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) != 0) {
}
String username = nameField.getText();
char[] password = passwordField.getPassword();

Labels: , ,


Comments: Post a Comment

Links to this post:

Create a Link



<< Home