/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * FrmLogin.java * * Created on 10/10/2010, 01:15:29 */ package boundary; import control.ControladoraLogin; import java.awt.event.KeyEvent; import java.sql.SQLException; import java.util.Vector; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import util.ConexaoException; import util.MinhaException; /** * * @author Rodrigo Martins */ public class FrmLogin extends javax.swing.JFrame{ private ControladoraLogin controlLogin = new ControladoraLogin(); private Vector usuarioTipo = new Vector(); private Vector usuario = new Vector(); public Vector getUsuario() { return usuario; } public Vector getUsuarioTipo() { return usuarioTipo; } public void setUsuarioTipo(Vector usuarioTipo) { this.usuarioTipo = usuarioTipo; } /** Creates new form FrmLogin */ public FrmLogin() { initComponents(); this.setLocationRelativeTo(null); this.setIconImage(new ImageIcon(getClass().getResource("/img/logo.png")).getImage()); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTFLogin = new javax.swing.JTextField(); jPFSenha = new javax.swing.JPasswordField(); jLabel3 = new javax.swing.JLabel(); jCBTipo = new javax.swing.JComboBox(); jBLogar = new javax.swing.JButton(); jBCancelar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle("SCC - Login"); setResizable(false); jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); jLabel1.setText("Login:"); jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 18)); jLabel2.setText("Senha:"); jTFLogin.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { jTFLoginKeyReleased(evt); } }); jPFSenha.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { jPFSenhaKeyReleased(evt); } }); jLabel3.setText("Tipo:"); jCBTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Funcionario", "Cliente" })); jCBTipo.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { jCBTipoKeyPressed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jTFLogin)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(jLabel3))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jCBTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPFSenha)))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jTFLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jPFSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jCBTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addContainerGap(26, Short.MAX_VALUE)) ); jBLogar.setText("Logar"); jBLogar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jBLogarActionPerformed(evt); } }); jBCancelar.setText("Cancelar"); jBCancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jBCancelarActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jBCancelar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jBLogar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jBLogar) .addComponent(jBCancelar)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed this.dispose(); }//GEN-LAST:event_jBCancelarActionPerformed @SuppressWarnings({"unchecked", "unchecked", "unchecked"}) private void jBLogarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLogarActionPerformed if (!this.jTFLogin.getText().isEmpty()) { if (this.jPFSenha.getPassword().length > 0) { String log = (new String(this.jPFSenha.getPassword())); Vector login = new Vector(); login.addElement(this.jTFLogin.getText()); login.addElement(log); login.addElement(this.jCBTipo.getSelectedItem()); if (login.get(0).equals("admin") && login.get(1).equals("admin")){ if (this.jCBTipo.getSelectedItem().equals("Funcionario")) { this.usuarioTipo.addElement("Funcionario"); } if (this.jCBTipo.getSelectedItem().equals("Cliente")) { this.usuarioTipo.addElement("Cliente"); } this.usuario.addElement(login); this.dispose(); new FrmPrincipalSCC(usuarioTipo,usuario).setVisible(true); } else{ try { try { if (this.jCBTipo.getSelectedItem().equals("Funcionario")) { this.usuarioTipo.addElement("Funcionario"); } if (this.jCBTipo.getSelectedItem().equals("Cliente")) { this.usuarioTipo.addElement("Cliente"); } this.usuario.addElement(this.controlLogin.consultaUsuario(login)); this.dispose(); new FrmPrincipalSCC(usuarioTipo,usuario).setVisible(true); } catch (MinhaException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } } catch (ConexaoException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } catch (SQLException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } } } else JOptionPane.showMessageDialog(this, "Informe o Login/Senha !", "Informação", JOptionPane.INFORMATION_MESSAGE); } else JOptionPane.showMessageDialog(this, "Informe o Login/Senha !", "Informação", JOptionPane.INFORMATION_MESSAGE); }//GEN-LAST:event_jBLogarActionPerformed private void jTFLoginKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTFLoginKeyReleased if(evt.getKeyCode() == KeyEvent.VK_ENTER) this.jPFSenha.grabFocus(); }//GEN-LAST:event_jTFLoginKeyReleased private void jPFSenhaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPFSenhaKeyReleased if(evt.getKeyCode() == KeyEvent.VK_ENTER) this.jCBTipo.grabFocus(); }//GEN-LAST:event_jPFSenhaKeyReleased private void jCBTipoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jCBTipoKeyPressed if(evt.getKeyCode() == KeyEvent.VK_ENTER) this.jBLogarActionPerformed(null); }//GEN-LAST:event_jCBTipoKeyPressed /** * @param args the command line arguments */ public static void main(String args[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new FrmLogin().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jBCancelar; private javax.swing.JButton jBLogar; private javax.swing.JComboBox jCBTipo; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPasswordField jPFSenha; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTFLogin; // End of variables declaration//GEN-END:variables }