Where The Streets Have No Name

JXLoginPane 예제 본문

Developement/Java

JXLoginPane 예제

highheat 2009. 11. 6. 10:44
import org.jdesktop.swingx.auth.LoginService;

public class DummyLoginService extends LoginService {

    @Override
    public boolean authenticate(String arg0, char[] arg1, String arg2) throws Exception {
        //throw new UnsupportedOperationException("Not supported yet.");
        System.out.println("name : " + arg0);
        StringBuilder passwd = new StringBuilder();
        for (char c : arg1) {
            passwd.append(c);
        }
        System.out.println("password : " + passwd.toString());
        System.out.println("server : " + arg2);
        
        if(passwd.toString().equals("9981"))
            return true;
        else
            return false;
    }
}

기본적으로 제공되는 로그인창을 사용하는 경우

    private void btnLoginMouseClicked(java.awt.event.MouseEvent evt) {                                      
        JXLoginPane.Status status = JXLoginPane.showLoginDialog(null, new DummyLoginService());        
        System.out.println("login status : "+status);
    }


사용자가 정의한 로그인 창을 사용하는 경우

private org.jdesktop.swingx.JXLoginPane customerLoginPane;
...
customerLoginPane = new org.jdesktop.swingx.JXLoginPane();
...
customerLoginPane.setBannerText("Customer Login");
  
private void btnLoginMouseClicked(java.awt.event.MouseEvent evt) {                                      
        customerLoginPane.setLoginService(new DummyLoginService());
        JXLoginPane.Status status = JXLoginPane.showLoginDialog(null,customerLoginPane);
        System.out.println("login status : "+status);
}