desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginAction.java
branchdesktop
changeset 263 ac802aa234fc
child 268 13fe01081e23
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginAction.java	Tue Sep 14 08:30:37 2010 +0200
     1.3 @@ -0,0 +1,34 @@
     1.4 +/*
     1.5 + * To change this template, choose Tools | Templates
     1.6 + * and open the template in the editor.
     1.7 + */
     1.8 +package cz.xelfi.quoridor.desktop.sample;
     1.9 +
    1.10 +import java.awt.event.ActionEvent;
    1.11 +import java.awt.event.ActionListener;
    1.12 +import org.openide.DialogDisplayer;
    1.13 +import org.openide.NotifyDescriptor;
    1.14 +import org.openide.util.NbBundle;
    1.15 +
    1.16 +public final class LoginAction implements ActionListener {
    1.17 +
    1.18 +    @Override
    1.19 +    public void actionPerformed(ActionEvent e) {
    1.20 +        LoginPanel lp = new LoginPanel();
    1.21 +        NotifyDescriptor nd = new NotifyDescriptor(
    1.22 +            lp,
    1.23 +            NbBundle.getMessage(LoginAction.class, "LoginAction.title"),
    1.24 +            NotifyDescriptor.OK_CANCEL_OPTION,
    1.25 +            NotifyDescriptor.QUESTION_MESSAGE, null, null
    1.26 +        );
    1.27 +        Object res = DialogDisplayer.getDefault().notify(nd);
    1.28 +        if (res == NotifyDescriptor.OK_OPTION) {
    1.29 +            if (!Quoridor.getDefault().login(lp.getLogin(), lp.getPassword())) {
    1.30 +                nd = new NotifyDescriptor.Message(
    1.31 +                    NbBundle.getMessage(LoginAction.class, "LoginAction.fail")
    1.32 +                );
    1.33 +                DialogDisplayer.getDefault().notify(nd);
    1.34 +            }
    1.35 +        }
    1.36 +    }
    1.37 +}