-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserCreateDialog.java
More file actions
187 lines (151 loc) · 5.07 KB
/
Copy pathUserCreateDialog.java
File metadata and controls
187 lines (151 loc) · 5.07 KB
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
package view;
import java.awt.Color;
import javax.swing.JDialog;
import Utils.HashSecurity;
import Utils.MessageBox;
import daoLibrary.UserDAO;
import modelsLibrary.User;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
public class UserCreateDialog extends JDialog {
private static final long serialVersionUID = 1L;
private JButton jButtonFechar;
private JTextField jtxtLogin;
private JPasswordField jpasswordSenha;
private JPasswordField jpasswordSenhaMaster;
private JLabel jlblLogin;
private JLabel jlblSenha;
private JLabel jlblSenhaMaster;
private JButton jbtnCadastrar;
private JCheckBox jchckbxSenha;
private JCheckBox jchckbxSenhaMaster;
/**Iniciando a tela
*
* @param args
*/
public static void main(String[] args) {
try {
UserCreateDialog dialog = new UserCreateDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Carregando a tela e os seus components e ações.
*/
public UserCreateDialog() {
initComponents();
actionButtons();
}
/**
* Construção da tela e seus components
* botão, caixas de textos e label(s).
*/
public void initComponents() {
getRootPane().setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.DARK_GRAY));
setUndecorated(true);
setBounds(100, 100, 472, 381);
setResizable(false);
setLocationRelativeTo(null);
setModal(true);
getContentPane().setLayout(null);
jButtonFechar = new JButton("Sair");
jButtonFechar.setBounds(405, 347, 57, 23);
getContentPane().add(jButtonFechar);
jtxtLogin = new JTextField();
jtxtLogin.setBounds(150, 81, 163, 20);
getContentPane().add(jtxtLogin);
jtxtLogin.setColumns(10);
jpasswordSenha = new JPasswordField();
jpasswordSenha.setBounds(150, 150, 163, 20);
getContentPane().add(jpasswordSenha);
jpasswordSenhaMaster = new JPasswordField();
jpasswordSenhaMaster.setBounds(150, 222, 163, 20);
getContentPane().add(jpasswordSenhaMaster);
jlblLogin = new JLabel("Login:");
jlblLogin.setBounds(150, 62, 46, 14);
getContentPane().add(jlblLogin);
jlblSenha = new JLabel("Senha:");
jlblSenha.setBounds(150, 131, 46, 14);
getContentPane().add(jlblSenha);
jlblSenhaMaster = new JLabel("Senha Master:");
jlblSenhaMaster.setBounds(150, 205, 85, 14);
getContentPane().add(jlblSenhaMaster);
jbtnCadastrar = new JButton("Cadastrar Novo Usuario");
jbtnCadastrar.setBounds(150, 269, 163, 40);
getContentPane().add(jbtnCadastrar);
jchckbxSenha = new JCheckBox("Ver");
jchckbxSenha.setBounds(315, 149, 46, 23);
getContentPane().add(jchckbxSenha);
jchckbxSenhaMaster = new JCheckBox("Ver");
jchckbxSenhaMaster.setBounds(315, 221, 46, 23);
getContentPane().add(jchckbxSenhaMaster);
}
/**
* Metodo criado para a ação dos botões da tela (Listeners)
*/
public void actionButtons() {
//Veriricação da senha Usuario, checkbox selecionado a senha fica vísivel.
jchckbxSenha.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jchckbxSenha.isSelected()) {
jpasswordSenha.setEchoChar((char) 0);
}else {
jpasswordSenha.setEchoChar('\u2022');
}
}
});
//Veriricação da senha Master, checkbox selecionado a senha fica vísivel.
jchckbxSenhaMaster.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jchckbxSenhaMaster.isSelected()) {
jpasswordSenhaMaster.setEchoChar((char) 0);
}else {
jpasswordSenhaMaster.setEchoChar('\u2022');
}
}
});
//Botão para cadastrar Usuario.
//Cadastroo do úsuario com criptografia Hash da senha.
jbtnCadastrar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
User user = new User();
UserDAO userDao = new UserDAO();
user.setLogin(jtxtLogin.getText());
String senhaLogin = HashSecurity.senhaCriptografada(new String(jpasswordSenha.getPassword()));
user.setSenha(senhaLogin);
String senhaMaster = HashSecurity.senhaCriptografada(new String (jpasswordSenhaMaster.getPassword()));
if (userDao.validarSenhaMaster(senhaMaster)) {
JOptionPane.showMessageDialog(null,"Senha: "+user.getSenha());
userDao.insertUser(user);
MessageBox.messageShow("Novo Úsuario cadastrado com sucesso!");
dispose();
}else {
MessageBox.messageShow("Senha Master incorreta!");
}
} catch (Exception e2) {
//Disparo de exceção caso o sistema não esteja conectado com o banco de dados
MessageBox.messageShow(e2.getMessage());
}
}
});
//Botão para fechar a tela dialog.
jButtonFechar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
}
}