SHARE
TWEET

Untitled

a guest Jun 17th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static Connection conectabd() throws ClassNotFoundException {
  2.  
  3.     try {
  4.         Class.forName("org.postgresql.Driver");
  5.          Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/crud","postgres","tmk9405");
  6.         JOptionPane.showMessageDialog(null,"Conectado com sucesso!");
  7.         return con;
  8.     }
  9.  
  10.     catch (SQLException error) {
  11.  
  12.         JOptionPane.showMessageDialog(null, error);
  13.         return null;
  14.     }  
  15. }
  16.      
  17. /**
  18.  *
  19.  */
  20. private static final long serialVersionUID = 1L;
  21. private JPanel contentPane;
  22.  
  23. /**
  24.  * Launch the application.
  25.  */
  26. public static void main(String[] args) {
  27.     EventQueue.invokeLater(new Runnable() {
  28.         public void run() {
  29.             try {
  30.                 frmLogin frame = new frmLogin();
  31.                 frame.setVisible(true);
  32.             } catch (Exception e) {
  33.                 e.printStackTrace();
  34.             }
  35.         }
  36.     });
  37. }
  38.  
  39. /**
  40.  * Create the frame.
  41.  */
  42.  
  43. Connection con = null;
  44. PreparedStatement pst = null;
  45. ResultSet rs = null;
  46. private JTextField txtUsuario;
  47. private JPasswordField txtSenha;
  48. private JLabel lblLogin;
  49. private JLabel lblSistemaDesenvolvidoPela;
  50.  
  51. public frmLogin() throws ClassNotFoundException {
  52.     setIconImage(Toolkit.getDefaultToolkit().getImage("C:\Users\Alessandro\Downloads\icons8-senha-50.png"));
  53.     setTitle("Login de usuu00E1rio");
  54.  
  55.  
  56.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57.     setBounds(100, 100, 640, 299);
  58.     contentPane = new JPanel();
  59.     contentPane.setBorder(new TitledBorder(null, "", TitledBorder.CENTER, TitledBorder.TOP, null, null));
  60.     setContentPane(contentPane);
  61.     contentPane.setLayout(null);
  62.  
  63.     JLabel lblUsurio = new JLabel("Usuu00E1rio:");
  64.     lblUsurio.setBounds(139, 70, 85, 20);
  65.     lblUsurio.setHorizontalAlignment(SwingConstants.CENTER);
  66.     lblUsurio.setFont(new Font("Arial", Font.BOLD, 12));
  67.     contentPane.add(lblUsurio);
  68.  
  69.     txtUsuario = new JTextField();
  70.     txtUsuario.setBounds(224, 73, 179, 20);
  71.     txtUsuario.setColumns(10);
  72.     contentPane.add(txtUsuario);
  73.  
  74.     JLabel lblSenha = new JLabel("senha:");
  75.     lblSenha.setBounds(139, 106, 85, 20);
  76.     lblSenha.setHorizontalAlignment(SwingConstants.CENTER);
  77.     lblSenha.setFont(new Font("Arial", Font.BOLD, 12));
  78.     contentPane.add(lblSenha);
  79.  
  80.     JButton btnEntrar = new JButton("ENTRAR");
  81.     btnEntrar.setIcon(new ImageIcon("C:\Users\Alessandro\Downloads\icones\Icones\accept.png"));
  82.     btnEntrar.setBounds(262, 166, 104, 23);
  83.     btnEntrar.addActionListener(new ActionListener() {
  84.         public void actionPerformed(ActionEvent arg0) {
  85.             Logar();
  86.         }
  87.     });
  88.  
  89.     txtSenha = new JPasswordField();
  90.     txtSenha.setBounds(224, 107, 179, 20);
  91.     contentPane.add(txtSenha);
  92.     contentPane.add(btnEntrar);
  93.  
  94.     lblLogin = new JLabel("LOGIN");
  95.     lblLogin.setFont(new Font("Arial", Font.BOLD, 15));
  96.     lblLogin.setBounds(262, 11, 67, 21);
  97.     contentPane.add(lblLogin);
  98.  
  99.     lblSistemaDesenvolvidoPela = new JLabel("Sistema desenvolvido por Alesssandro Jacques.)");
  100.     lblSistemaDesenvolvidoPela.setForeground(Color.BLACK);
  101.     lblSistemaDesenvolvidoPela.setFont(new Font("SansSerif", Font.PLAIN, 10));
  102.     lblSistemaDesenvolvidoPela.setBounds(233, 256, 391, 14);
  103.     contentPane.add(lblSistemaDesenvolvidoPela);
  104.     this.setLocationRelativeTo(null); // centralizando formulario
  105.     con = conectaBD.conectabd();
  106.  
  107.     setResizable(false); //Bloquando a opção maximizar a tela de login
  108. }
  109.     @SuppressWarnings("deprecation")
  110.     public void Logar() {
  111.         String sql = "Select * from login where usuario = ? and senha = ?";
  112.         try {
  113.             pst = con.prepareStatement(sql);
  114.             pst.setString(1, txtUsuario.getText());
  115.             pst.setString(2, txtSenha.getText());
  116.  
  117.             rs = pst.executeQuery();
  118.  
  119.             if(rs.next()) {
  120.                 frmPrincipal frm = new frmPrincipal();
  121.                 frm.setVisible(true);
  122.                 dispose();
  123.             }else {
  124.                 JOptionPane.showMessageDialog(null,"Usuario e senha inválidos.");
  125.             }
  126.         }
  127.         catch(SQLException error) {
  128.             JOptionPane.showMessageDialog(null, error);
  129.         }
  130.     }
  131.  
  132. }
  133.      
  134. private static final long serialVersionUID = 1L;
  135. private JPanel contentPane;
  136. private JTextField txtBusca;
  137. private JButton btnLimpar;
  138. private JButton btnSair;
  139.  
  140. public static void main(String[] args) {
  141.     EventQueue.invokeLater(new Runnable() {
  142.  
  143.         public void run() {
  144.             try {
  145.                 frmPrincipal frame = new frmPrincipal();
  146.                 frame.setVisible(true);
  147.             } catch (Exception e) {
  148.                 e.printStackTrace();
  149.             }
  150.         }
  151.     });
  152. }
  153.  
  154. Connection conectabd=null;
  155.  
  156. /**
  157.  * Create the frame.
  158.  */
  159. public frmPrincipal() {
  160.  
  161.     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  162.     setBounds(100, 100, 1124, 744);
  163.     contentPane = new JPanel();
  164.     contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  165.     setContentPane(contentPane);
  166.     contentPane.setLayout(null);
  167.  
  168.     JLabel lblPesquisar = new JLabel("Pesquisar:");
  169.     lblPesquisar.setBounds(50, 52, 85, 33);
  170.     lblPesquisar.setFont(new Font("Tahoma", Font.PLAIN, 18));
  171.     contentPane.add(lblPesquisar);
  172.  
  173.     txtBusca = new JTextField();
  174.     txtBusca.setBounds(140, 62, 260, 23);
  175.     txtBusca.setColumns(10);
  176.     contentPane.add(txtBusca);
  177.     //pesquisarUsuarios();
  178.  
  179.     JButton btnBuscar = new JButton("Buscar");
  180.     btnBuscar.setBounds(410, 60, 108, 23);
  181.     btnBuscar.addActionListener(new ActionListener() {
  182.         public void actionPerformed(ActionEvent arg0) {
  183.  
  184.         }
  185.     });
  186.     btnBuscar.setIcon(new ImageIcon("C:\Users\Alessandro\Downloads\icons8-pesquisar-filled-25.png"));
  187.     contentPane.add(btnBuscar);
  188.  
  189.     btnLimpar = new JButton("Limpar ");
  190.     btnLimpar.setIcon(new ImageIcon("C:\Users\Alessandro\Downloads\icons8-limpar-pesquisa-25.png"));
  191.     btnLimpar.addActionListener(new ActionListener() {
  192.         public void actionPerformed(ActionEvent e) {
  193.             txtBusca.setText(null);
  194.  
  195.         }
  196.     });
  197.     btnLimpar.setBounds(523, 107, 115, 23);
  198.     contentPane.add(btnLimpar);
  199.  
  200.     btnSair = new JButton("SAIR");
  201.     btnSair.addActionListener(new ActionListener() {
  202.         public void actionPerformed(ActionEvent e) {
  203.             System.exit(0);
  204.         }
  205.     });
  206.     btnSair.setBounds(410, 107, 108, 23);
  207.     btnSair.setFont(new Font("Tahoma", Font.BOLD, 11));
  208.     btnSair.setIcon(new ImageIcon("C:\Users\Alessandro\Downloads\icons8-fechar-janela-25.png"));
  209.     contentPane.add(btnSair);
  210.  
  211.     this.setExtendedState(MAXIMIZED_BOTH); // utiliza para maximizar o formulário
  212.     //setResizable(false); //Bloquando a opção maximizar
  213.  
  214.     setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); //tirando a opção fechar o JFRAME
  215.  
  216. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top