5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.WindowAdapter;
8 import java.awt.event.WindowEvent;
10 import javax.swing.JButton;
11 import javax.swing.JFrame;
12 import javax.swing.JLabel;
13 import javax.swing.JOptionPane;
14 import javax.swing.JPanel;
15 import javax.swing.JPasswordField;
16 import javax.swing.JTextField;
17 import javax.swing.SwingConstants;
18 import javax.swing.border.EmptyBorder;
20 import businessLogic.BLFacade;
21 import domain.AdminUser;
22 import domain.RegularUser;
23 import java.awt.Color;
24 import java.awt.SystemColor;
26 public class LoginGUI extends JFrame {
28 private JPanel contentPane;
29 private JTextField textUser;
30 private JPasswordField textPass;
31 private static BLFacade facade;
32 private static RegularUser userlog;
34 private JLabel lblUser = new JLabel("Usuario:");
35 private JLabel lblPass = new JLabel("Contraseña:");
37 private JButton buttonLogin = new JButton("Login");
38 private JButton buttonRegister = new JButton("Registrarse");
39 private JButton btnInvitado;
44 addWindowListener(new WindowAdapter() {
46 public void windowClosing(WindowEvent e) {
48 // if (ConfigXML.getInstance().isBusinessLogicLocal()) facade.close();
49 } catch (Exception e1) {
51 "Error: " + e1.toString() + " , probably problems with Business Logic or Database");
58 // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
61 public void initialize() {
64 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
65 setBounds(100, 100, 460, 300);
66 contentPane = new JPanel();
67 contentPane.setBackground(Color.WHITE);
68 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
69 setContentPane(contentPane);
70 contentPane.setLayout(null);
72 lblUser.setHorizontalAlignment(SwingConstants.RIGHT);
73 lblUser.setBounds(65, 66, 100, 14);
74 contentPane.add(lblUser);
76 lblPass.setHorizontalAlignment(SwingConstants.RIGHT);
77 lblPass.setBounds(89, 106, 76, 14);
78 contentPane.add(lblPass);
80 textUser = new JTextField("");
81 textUser.setForeground(Color.GRAY);
82 textUser.setFont(new Font("Arial", Font.PLAIN, 16));
83 textUser.setBounds(175, 57, 135, 30);
84 contentPane.add(textUser);
85 textUser.setColumns(10);
87 textPass = new JPasswordField("");
88 textPass.setForeground(Color.GRAY);
89 textPass.setFont(new Font("Arial", Font.PLAIN, 16));
90 textPass.setBounds(175, 97, 135, 30);
91 contentPane.add(textPass);
92 textPass.setColumns(10);
93 buttonLogin.setForeground(Color.WHITE);
94 buttonLogin.setFont(new Font("Dialog", Font.BOLD, 14));
95 buttonLogin.setBackground(SystemColor.textHighlight);
97 buttonLogin.addActionListener(new ActionListener() {
99 public void actionPerformed(ActionEvent arg0) {
100 String pass = String.valueOf(textPass.getPassword());
101 String userName = textUser.getText();
102 if (pass.equals("") || userName.equals("")) {
103 JOptionPane.showMessageDialog(contentPane, "Usuario o contraseña no introducida", "Error",
104 JOptionPane.ERROR_MESSAGE);
106 boolean b = facade.doLogin(userName, pass);
109 // Check user permissions
110 if (facade.isAdmin(userName, pass)) {
112 AdminUser au = facade.getAdminUserByUsername(userName);
113 JFrame a = new MainAdminGUI(au);
114 // a.setLocationRelativeTo(null);
116 textUser.setText("");
117 textPass.setText("");
121 RegularUser ru = facade.getRegularUserByUsername(userName);
122 JFrame a = new MainGUI(ru);
123 // a.setLocationRelativeTo(null);
125 textUser.setText("");
126 textPass.setText("");
130 JOptionPane.showMessageDialog(null, "Usuario y contraseña no coinciden", "LOGIN INFO",
131 JOptionPane.ERROR_MESSAGE, null);
137 buttonLogin.setBounds(97, 155, 89, 27);
138 contentPane.add(buttonLogin);
139 buttonRegister.setFont(new Font("Dialog", Font.BOLD, 14));
140 buttonRegister.setForeground(Color.WHITE);
141 buttonRegister.setBackground(SystemColor.textHighlight);
143 buttonRegister.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent e) {
147 Frame reg = new RegisterGUI();
148 reg.setAlwaysOnTop(true);
149 reg.setVisible(true);
154 buttonRegister.setBounds(220, 155, 135, 27);
155 contentPane.add(buttonRegister);
157 btnInvitado = new JButton("Invitado");
158 btnInvitado.addActionListener(new ActionListener() {
159 public void actionPerformed(ActionEvent arg0) {
160 Frame reg = new FindQuestionsInvitadoGUI();
161 reg.setAlwaysOnTop(true);
162 reg.setVisible(true);
166 btnInvitado.setForeground(Color.WHITE);
167 btnInvitado.setFont(new Font("Dialog", Font.BOLD, 14));
168 btnInvitado.setBackground(SystemColor.textHighlight);
169 btnInvitado.setBounds(145, 204, 120, 27);
170 contentPane.add(btnInvitado);
174 public static void setBusinessLogic(BLFacade pfacade) {
178 public static BLFacade getBusinessLogic() {
182 public void setRegularUserLog(RegularUser user) {
183 LoginGUI.userlog = user;
186 public static RegularUser getUserLog() {