5 import java.awt.KeyEventDispatcher;
6 import java.awt.KeyboardFocusManager;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.awt.event.KeyEvent;
10 import java.awt.event.WindowAdapter;
11 import java.awt.event.WindowEvent;
12 import java.rmi.Naming;
13 import java.rmi.RemoteException;
15 import javax.swing.JButton;
16 import javax.swing.JFrame;
17 import javax.swing.JLabel;
18 import javax.swing.JPanel;
19 import javax.swing.JPasswordField;
20 import javax.swing.JTextField;
21 import javax.swing.SwingConstants;
23 import common.LoginInterface;
25 import configuration.___IntNames;
26 import domain.Account;
28 public class LoginGUI extends JFrame {
30 private static final long serialVersionUID= 1L;
31 private JPanel jContentPane = null;
32 private JTextField usernameField;
33 private JPasswordField passwordField;
34 private LoginInterface loginManager = null;
35 private JLabel loginFeedback;
36 private JButton btnRegister;
37 protected boolean isFocused = false;
43 private void initialize() {
45 loginManager = (LoginInterface) Naming
46 .lookup(___IntNames.LoginManager);
47 } catch (Exception e1) {
48 System.out.println("Error accessing remote authentication: "
51 this.setSize(449, 293);
52 this.setContentPane(getJContentPane());
53 this.setTitle("Login");
54 addWindowListener(new WindowAdapter() {
58 public void windowGainedFocus(WindowEvent e) {
63 public void windowLostFocus(WindowEvent e) {
68 KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
71 public boolean dispatchKeyEvent(KeyEvent e) {
72 if (isFocused && e.getKeyCode() == KeyEvent.VK_ENTER )
73 jButton_ActionPerformed();
80 private JPanel getJContentPane() {
81 if (jContentPane == null) {
82 jContentPane = new JPanel();
83 jContentPane.setLayout(null);
85 JLabel usernameTag = new JLabel("Username:");
86 usernameTag.setBounds(56, 67, 104, 20);
87 jContentPane.add(usernameTag);
89 JLabel passwordTag = new JLabel("Password:");
90 passwordTag.setBounds(56, 132, 104, 15);
91 jContentPane.add(passwordTag);
93 usernameField = new JTextField();
94 usernameField.setBounds(202, 65, 133, 25);
95 jContentPane.add(usernameField);
96 usernameField.setColumns(10);
98 passwordField = new JPasswordField();
99 passwordField.setBounds(202, 122, 133, 25);
100 jContentPane.add(passwordField);
102 JButton loginButton = new JButton("Login");
103 loginButton.addActionListener(new ActionListener() {
104 public void actionPerformed(ActionEvent arg0) {
106 jButton_ActionPerformed();
109 loginButton.setBounds(95, 179, 117, 25);
110 jContentPane.add(loginButton);
112 loginFeedback = new JLabel("");
113 loginFeedback.setForeground(Color.RED);
114 loginFeedback.setHorizontalAlignment(SwingConstants.CENTER);
115 loginFeedback.setBounds(83, 216, 269, 25);
116 jContentPane.add(loginFeedback);
118 btnRegister = new JButton("Register");
119 btnRegister.setBounds(222, 180, 113, 23);
120 btnRegister.addActionListener(new ActionListener() {
121 public void actionPerformed(ActionEvent arg0) {
123 jButton_ActionPerformed2(arg0);
126 jContentPane.add(btnRegister);
130 private void jButton_ActionPerformed2(ActionEvent e){
133 this.setVisible(false);
134 Frame a = new OwnerRegistrationGUI();
142 private void jButton_ActionPerformed(){
146 acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
147 } catch (RemoteException e) {
148 // TODO Auto-generated catch block
151 if (acc == null) loginFeedback.setText("Incorrect username or password");
152 else if( acc.getAdmin()) {
153 this.setVisible(false);
154 Frame a = new AdminMenuGUI();
157 if(acc.getOwner()==null){
158 loginFeedback.setText("Incorrect username or password");
160 this.setVisible(false);
161 Frame a = new OwnerMenuGUI(acc.getOwner());
167 } // @jve:decl-index=0:visual-constraint="222,33"