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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235package run;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
<<<<<<< HEAD
=======
>>>>>>> 2f262421643b46e7d4cef894850163803f9a06b8
import javax.swing.border.LineBorder;
import GUI.RoundJPasswordField;
import GUI.RoundJTextField;
<<<<<<< HEAD
import DAO.TaiKhoanDAO;
import DTO.TAIKHOAN;
=======
import DAO.TaiKhoanDAO;
import DTO.TAIKHOAN;
>>>>>>> 2f262421643b46e7d4cef894850163803f9a06b8
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
<<<<<<< HEAD
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
import java.lang.classfile.instruction.NewMultiArrayInstruction;
import java.util.Arrays;
=======
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
//import java.lang.classfile.instruction.NewMultiArrayInstruction;
import java.util.Arrays;
>>>>>>> 2f262421643b46e7d4cef894850163803f9a06b8
public class loginFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private RoundJTextField textField;
private JPasswordField passwordField;
private boolean isLogin = false;
Color FontColor = new Color(108, 188, 231);
public loginFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(950, 450);
setUndecorated(true);
setLocationRelativeTo(null);
setTitle("Login");
// Content Pane
contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
// Left Panel
JPanel leftPanel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(new Color(204, 229, 255));
g.fillRect(0, 0, getWidth(), getHeight());
}
};
leftPanel.setPreferredSize(new Dimension(400, 400));
leftPanel.setLayout(new BorderLayout());
contentPane.add(leftPanel, BorderLayout.WEST);
ImageIcon welcomeIcon = new ImageIcon("src/assets/appIcon/R.png");
welcomeIcon = resizeIcon(welcomeIcon, 300, 300);
JLabel welcomeLabel = new JLabel(welcomeIcon, JLabel.CENTER);
leftPanel.add(welcomeLabel, BorderLayout.CENTER);
// Right Panel
JPanel rightPanelContainer = new JPanel(new BorderLayout());
contentPane.add(rightPanelContainer, BorderLayout.CENTER);
JPanel rightPanel = new JPanel(new BorderLayout());
rightPanelContainer.add(rightPanel, BorderLayout.CENTER);
JPanel loginPanel = new JPanel(new GridBagLayout());
loginPanel.setBackground(Color.white);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.anchor = GridBagConstraints.WEST;
// Label "Đăng nhập hệ thống"
JLabel loginSystemLabel = new JLabel("Đăng nhập hệ thống");
loginSystemLabel.setFont(new Font("Tahoma", Font.BOLD, 20));
loginSystemLabel.setForeground(Color.BLACK);
gbc.anchor = GridBagConstraints.CENTER;
loginPanel.add(loginSystemLabel, gbc);
gbc.gridy++;
ImageIcon accountIcon = new ImageIcon("src/assets/appIcon/icons8-user-24.png");
accountIcon = resizeIcon(accountIcon, 20, 20);
JLabel lblNewLabel = new JLabel("Tài Khoản", accountIcon, JLabel.LEFT);
gbc.anchor= GridBagConstraints.WEST;
loginPanel.add(lblNewLabel, gbc);
gbc.gridy++;
textField = new RoundJTextField(25);
textField.setBorder(new RoundedBorder(10));
textField.setPreferredSize(new Dimension(250, 30));
loginPanel.add(textField, gbc);
gbc.gridy++;
ImageIcon passwordIcon = new ImageIcon("src/assets/appIcon/icons8-password-50.png");
passwordIcon = resizeIcon(passwordIcon, 20, 20);
JLabel lblNewLabel_1 = new JLabel("Mật Khẩu", passwordIcon, JLabel.LEFT);
loginPanel.add(lblNewLabel_1, gbc);
gbc.gridy++;
passwordField= new JPasswordField();
passwordField.setBorder(new RoundedBorder(10));
passwordField.setPreferredSize(new Dimension(250, 30));
loginPanel.add(passwordField, gbc);
gbc.gridy++;
// Biểu tượng nút đăng nhập từ file cục bộ, được điều chỉnh kích thước
ImageIcon loginButtonIcon = new ImageIcon("src/assets/appIcon/icons8-login-50.png");
loginButtonIcon = resizeIcon(loginButtonIcon, 20, 20);
JButton btnNewButton = new JButton("Đăng Nhập", loginButtonIcon);
btnNewButton.setPreferredSize(new Dimension(250,30));
btnNewButton.setBorderPainted(false);
//btnNewButton.setContentAreaFilled(false);
btnNewButton.setBorder(new RoundedBorder(10));
gbc.anchor = GridBagConstraints.CENTER;
gbc.insets = new Insets(20, 0, 0, 0);
//gbc.gridwidth = 5; // Tăng chiều dài của nút đăng nhập lên 2 ô
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent evt) {
btnNewButton.setBackground(FontColor);
btnNewButton.setForeground(Color.black);
}
@Override
public void mouseExited(MouseEvent evt) {
btnNewButton.setBackground(new Color(46, 129, 223));
btnNewButton.setForeground(Color.white);
}
});
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
checkLogin();
}
});
btnNewButton.setBackground(new Color(46, 129, 223));
btnNewButton.setForeground(Color.BLACK);
loginPanel.add(btnNewButton, gbc);
rightPanel.add(loginPanel, BorderLayout.CENTER);
}
private ImageIcon resizeIcon(ImageIcon icon, int width, int height) {
Image img = icon.getImage();
Image resizedImg = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
return new ImageIcon(resizedImg);
}
public boolean getIsLogin() {
return this.isLogin;
}
private static class RoundedBorder implements Border {
private int radius;
public RoundedBorder(int radius) {
this.radius = radius;
}
@Override
public Insets getBorderInsets(Component c) {
return new Insets(this.radius, this.radius , this.radius , this.radius);
}
@Override
public boolean isBorderOpaque() {
return true;
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.setColor(Color.BLACK);
((Graphics2D) g).draw(new RoundRectangle2D.Double(x, y, width - 1, height - 1, radius, radius));
}
}
public void checkLogin() {
String input_taikhoan = textField.getText();
char[] input_maukhau = passwordField.getPassword();
String input_maukhau_str = new String(input_maukhau);
if (input_taikhoan.equals("") || input_maukhau_str.equals(""))
JOptionPane.showMessageDialog(this, "Vui lòng nhập đầy đủ", "Cảnh báo!", JOptionPane.WARNING_MESSAGE);
else {
TAIKHOAN tk = TaiKhoanDAO.getInstance().getTAIKHOAN(input_taikhoan);
if (tk == null)
JOptionPane.showMessageDialog(this, "Tài khoản không tồn tại", "Cảnh báo!", JOptionPane.WARNING_MESSAGE);
else {
if (tk.getPass().equals(input_maukhau_str)) {
// login
dispose();
appFrame app = new appFrame();
app.setVisible(true);
isLogin = true;
}
else
JOptionPane.showMessageDialog(this, "Mật khẩu không khớp", "Cảnh báo!", JOptionPane.WARNING_MESSAGE);
}
}
// Clear the password for security
Arrays.fill(input_maukhau, '0');
}
}