-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemStartView.java
More file actions
211 lines (170 loc) · 5.77 KB
/
Copy pathSystemStartView.java
File metadata and controls
211 lines (170 loc) · 5.77 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package view;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import Utils.MessageBox;
import modelsLibrary.User;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import java.util.HexFormat;
import java.security.MessageDigest;
import javax.swing.JPasswordField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JCheckBox;
public class SystemStartView extends JFrame {
private static final long serialVersionUID = 1L;
/**
* Instaciando os componentes da tela globalmente
*/
private JPanel contentPane;
private JPasswordField jpasswordFieldSenha;
private JButton jbtnIniciar;
private JButton jbtnExit;
private JLabel jlblNewLabelLogin;
private JLabel jlblNewLabelSenha;
private JTextField jtextFieldLogin;
private JLabel jlblCadastrar;
private JCheckBox jchckbxVer;
/**Iniciando a tela
*
* @param args
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SystemStartView frame = new SystemStartView();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Carregando a tela e os seus components e ações.
*/
public SystemStartView() {
initComponents();
actionButtons();
}
/**
* Construção da tela e seus components
* botão, caixas de textos e label(s).
*/
public void initComponents() {
setType(Type.UTILITY);
setLocationRelativeTo(null);
getRootPane().setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.DARK_GRAY));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 558, 404);
setResizable(false);
setLocationRelativeTo(null);
getContentPane().setLayout(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
jbtnIniciar = new JButton("Iniciar");
jbtnIniciar.setBounds(197, 200, 145, 71);
contentPane.add(jbtnIniciar);
jbtnExit = new JButton("Encerrar");
jbtnExit.setFocusPainted(false);
jbtnExit.setBorder(null);
jbtnExit.setBackground(new Color(192, 192, 192));
jbtnExit.setBounds(437, 331, 95, 23);
contentPane.add(jbtnExit);
jtextFieldLogin = new JTextField();
jtextFieldLogin.setToolTipText("");
jtextFieldLogin.setBounds(197, 80, 145, 20);
contentPane.add(jtextFieldLogin);
jtextFieldLogin.setColumns(10);
jpasswordFieldSenha = new JPasswordField();
jpasswordFieldSenha.setBounds(197, 142, 145, 20);
contentPane.add(jpasswordFieldSenha);
jlblNewLabelLogin = new JLabel("Login:");
jlblNewLabelLogin.setBounds(197, 63, 46, 14);
contentPane.add(jlblNewLabelLogin);
jlblNewLabelSenha = new JLabel("Senha:");
jlblNewLabelSenha.setBounds(197, 124, 46, 14);
contentPane.add(jlblNewLabelSenha);
jlblCadastrar = new JLabel("Cadastrar novo Usuario");
jlblCadastrar.setHorizontalAlignment(SwingConstants.CENTER);
jlblCadastrar.setFont(new Font("Verdana", Font.PLAIN, 10));
jlblCadastrar.setForeground(Color.BLUE);
jlblCadastrar.setBounds(197, 282, 145, 14);
contentPane.add(jlblCadastrar);
jchckbxVer = new JCheckBox("Ver");
jchckbxVer.setFont(new Font("Tahoma", Font.PLAIN, 13));
jchckbxVer.setBounds(348, 141, 46, 23);
contentPane.add(jchckbxVer);
}
/**
* Metodo criado para a ação dos botões, labele checkbox da tela (Listeners).
*/
public void actionButtons() {
//Veriricação da senha, checkbox selecionado a senha fica vísivel.
jchckbxVer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jchckbxVer.isSelected()) {
jpasswordFieldSenha.setEchoChar((char) 0);
}else {
jpasswordFieldSenha.setEchoChar('\u2022');
}
}
});
//Chama a tela de cadastrar Usuario.
jlblCadastrar.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
UserCreateDialog user = new UserCreateDialog();
user.setVisible(true);
}
});
// Encerra a execução do sistema ao clicar em Sair.
jbtnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
//Botão para verificação do login. Verificar se o usuario esta correto
//e em seguida liberar o acesso para a tela inicial do sistema.
jbtnIniciar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
User usuario = new User();
usuario.setLogin(jtextFieldLogin.getText());
usuario.setSenha(new String (jpasswordFieldSenha.getPassword()));
if (usuario.getLogin().equals("system") && usuario.getSenha().equals("system")) {
try {
//Contrução teste para a criação de criptografia para a senha do usuario.
MessageDigest codi = MessageDigest.getInstance("SHA-256");
byte[] hashBytes = codi.digest(usuario.getSenha().getBytes());
String protecao = HexFormat.of().formatHex(hashBytes);
MessageBox.messageShow("Senha criptografada: "+protecao);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null,"Erro no main. Erro: "+ex);
}
//Menssagem de acesso liberado e em seguida construção da tela principal
//e fechamento da tela de login.
MessageBox.messageShow("Acesso ao sistema autorizado");
MainView tlPrincipal = new MainView();
tlPrincipal.setVisible(true);
dispose();
} else {
MessageBox.messageShow("Login ou Senha incorreta!");
}
}
});
}
}