Git Repository Public Repository

ISBets21MAUBRY

URLs

Copy to Clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package gui;

import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ResourceBundle;

import javax.persistence.Entity;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import businessLogic.BLFacade;
import businessLogic.BLFacadeImplementation;
import domain.User;
import exceptions.IncorrectPassException;
import exceptions.UserDoesNotExistException;
import java.awt.Font;

public class LoginGUI extends JFrame {

	private JPanel contentPane;
	private JTextField textUser;
	private JPasswordField textPass;
	private static BLFacade facade;
	private static User user;

	private JLabel lblUser = new JLabel("Usuario:");
	private JLabel lblPass = new JLabel("Contrase�a:");

	private JButton buttonLogin = new JButton("Login");
	private JButton buttonRegister = new JButton("Registrarse");

	
	public LoginGUI() {
		super();
		
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				try {
					//if (ConfigXML.getInstance().isBusinessLogicLocal()) facade.close();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					System.out.println("Error: "+e1.toString()+" , probably problems with Business Logic or Database");
				}
				System.exit(1);
			}
		});

		initialize();
		//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	
	
	public void initialize() {
		setTitle("Login");

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		lblUser.setHorizontalAlignment(SwingConstants.RIGHT);
		lblUser.setBounds(39, 47, 100, 14);
		contentPane.add(lblUser);

		lblPass.setHorizontalAlignment(SwingConstants.RIGHT);
		lblPass.setBounds(63, 87, 76, 14);
		contentPane.add(lblPass);

		textUser = new JTextField();
		textUser.setFont(new Font("Liberation Sans", Font.PLAIN, 13));
		textUser.setBounds(149, 45, 131, 20);
		contentPane.add(textUser);
		textUser.setColumns(10);

		textPass = new JPasswordField();
		textPass.setFont(new Font("Liberation Sans", Font.PLAIN, 13));
		textPass.setBounds(149, 85, 131, 20);
		contentPane.add(textPass);
		textPass.setColumns(10);

		buttonLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					String pass = String.valueOf(textPass.getPassword());
					String userName = textUser.getText();
					if (pass.equals("") || userName.equals("")) {
						JOptionPane.showMessageDialog(contentPane, "Usuario o contrase�a no introducida", "Error",
								JOptionPane.ERROR_MESSAGE);
					}
					else {
					User user = facade.login(userName, pass);
					System.out.println("LOGIN CORRECTO");
					System.out.println(user.getUserName() + " " + user.getUserPass());

					if(user.getType()==0) {
						Frame gui = new MainGUI();
						gui.setAlwaysOnTop(true);
						gui.setVisible(true);
					}else {
						Frame gui = new MainAdminGUI();
						gui.setAlwaysOnTop(true);
						gui.setVisible(true);
					}

					dispose();
					}
				} catch (UserDoesNotExistException e) {
					JOptionPane.showMessageDialog(contentPane, e.getMessage() , "Error", JOptionPane.ERROR_MESSAGE);
				} catch (IncorrectPassException a) {
					JOptionPane.showMessageDialog(contentPane, a.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
				} catch (Exception e) {
					JOptionPane.showMessageDialog(getContentPane(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
				} finally {
					textPass.setText("");
					textUser.setText("");
				}
			}
		});

		
		buttonLogin.setBounds(97, 134, 89, 23);
		contentPane.add(buttonLogin);
		
		buttonRegister.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Frame reg = new RegisterGUI();
				reg.setAlwaysOnTop(true);
				reg.setVisible(true);
				dispose();
			}
		});

		buttonRegister.setBounds(220, 134, 135, 23);
		contentPane.add(buttonRegister);
		
	}

	public static void setBusinessLogic(BLFacade pfacade) {
		facade = pfacade;
	}

	public static BLFacade getBusinessLogic() {
		return facade;
	}

	public void setUser(User user) {
		LoginGUI.user = user;
	}

	public static User getUser() {
		return user;
	}
}

Commits for ISBets21MAUBRY/eclipse-workspace/ISBets21BRYMAUJONUNA/src/main/java/gui/LoginGUI.java

Diff revisions: vs.
Revision Author Commited Message
cbae14 ... porkipig Thu 04 Mar, 2021 10:33:41 +0000

Versión del proyecto de Apuestas tras la iteración 1