import java.awt.Component;
public class FrmLogin extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JLayeredPane contentPane;
private JTextField txtCpf;
private JButton btnCancelar;
private JButton btnNovaConta;
private JButton btnConfirmar;
private JLabel lblNewLabel;
private JTextField txtSenha;
private JCheckBox txtExibirSenha;
private JPasswordField txtpasswordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FrmLogin frame = new FrmLogin();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public FrmLogin() {
setUndecorated(true);
setIconImage(Toolkit.getDefaultToolkit().getImage(FrmLogin.class.getResource("/com/sun/java/swing/plaf/windows/icons/Computer.gif")));
setTitle("LOGIN");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 588, 319);
contentPane = new JLayeredPane();
contentPane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
contentPane.setToolTipText("Tela de Login");
contentPane.setBorder(new LineBorder(SystemColor.activeCaption, 2));
setContentPane(contentPane);
txtCpf = new JTextField();
txtCpf.setBounds(272, 44, 280, 48);
txtCpf.requestFocus();
contentPane.setLayout(null);
txtCpf.setFont(new Font("Segoe UI Light", Font.PLAIN, 20));
txtCpf.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(txtCpf);
txtCpf.setColumns(10);
btnConfirmar = new JButton("Confirmar");
btnConfirmar.setToolTipText("");
btnConfirmar.setBounds(427, 234, 125, 48);
btnConfirmar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String cpf = txtCpf.getText();
@SuppressWarnings("deprecation")
String senha = txtSenha.getText();
UsuarioDao usuarioDao = new UsuarioDao();
try {
if(usuarioDao.validarLogin(cpf, senha)){
new FrmPrincipal().setVisible(true);
dispose();
}else{
JOptionPane.showMessageDialog(null, "Usuário ou senha inválido.", "WARNING", JOptionPane.WARNING_MESSAGE);
txtCpf.setText("");
txtSenha.setText("");
txtCpf.requestFocus();
}
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "Erro ao acessar a base de dados.", "ERROR", JOptionPane.ERROR_MESSAGE);
e1.printStackTrace();
}
}
});
btnConfirmar.setIcon(
new ImageIcon(FrmLogin.class.getResource("/com/sun/java/swing/plaf/windows/icons/ListView.gif")));
contentPane.add(btnConfirmar);
btnCancelar = new JButton("Cancelar");
btnCancelar.setMnemonic('C');
btnCancelar.setFocusable(false);
btnCancelar.setBounds(280, 234, 125, 48);
btnCancelar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnCancelar.setIcon(new ImageIcon(
FrmLogin.class.getResource("/com/sun/javafx/scene/web/skin/DecreaseIndent_16x16_JFX.png")));
contentPane.add(btnCancelar);
btnNovaConta = new JButton("Nova Conta");
btnNovaConta.setMnemonic('N');
btnNovaConta.setFocusable(false);
btnNovaConta.setBounds(134, 234, 125, 48);
btnNovaConta.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmUsuario novoUsuario = new FrmUsuario();
novoUsuario.setVisible(true);
dispose();
}
});
btnNovaConta.setIcon(new ImageIcon(
FrmLogin.class.getResource("/com/sun/javafx/scene/web/skin/IncreaseIndent_16x16_JFX.png")));
contentPane.add(btnNovaConta);
lblNewLabel = new JLabel("");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setIcon(new ImageIcon(FrmLogin.class.getResource("/images/1494390215_mac-trashcan_full-new.png")));
lblNewLabel.setBounds(10, 11, 244, 212);
contentPane.add(lblNewLabel);
JLabel lblSenha = new JLabel("SENHA");
lblSenha.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblSenha.setHorizontalAlignment(SwingConstants.LEFT);
lblSenha.setBounds(272, 111, 88, 30);
contentPane.add(lblSenha);
JLabel lblCpf = new JLabel("CPF");
lblCpf.setHorizontalAlignment(SwingConstants.LEFT);
lblCpf.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblCpf.setBounds(272, 11, 88, 34);
contentPane.add(lblCpf);
txtExibirSenha = new JCheckBox("Exibir senha");
txtExibirSenha.setBounds(272, 194, 97, 23);
contentPane.add(txtExibirSenha);
txtSenha = new JTextField();
txtSenha.setBounds(272, 139, 280, 48);
contentPane.add(txtSenha);
txtSenha.setColumns(10);
txtpasswordField = new JPasswordField();
txtpasswordField.setBounds(272, 139, 280, 48);
contentPane.add(txtpasswordField);
txtpasswordField.setColumns(10);
if (txtExibirSenha.isSelected()) {
txtpasswordField.setVisible(false);
txtSenha.setVisible(true);
}
else {
txtSenha.setVisible(false);
txtpasswordField.setVisible(true);
}
}
}