Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package study_java_swing;
- import java.sql.*;
- import javax.swing.JOptionPane;
- /**
- *
- * @author FPT SHOP
- */
- public class LoginForm extends javax.swing.JFrame {
- private Connection conn = null;
- private Statement stmt = null;
- private ResultSet res = null;
- private final String ip_DB = "jdbc:mysql://localhost:3306/";
- private final String user_DB = "root";
- private final String pass_DB = "";
- /**
- * Creates new form LoginForm
- */
- public LoginForm() {
- initComponents();
- setLocationRelativeTo(null);
- }
- private void getDB(String sql){
- try{
- res = stmt.executeQuery(sql);
- System.out.println("Lấy Database thành công!!");
- }
- catch(Exception e){
- System.out.println("Lấy Database thất bại!!");
- }
- }
- private boolean UpdateDB(String sql){
- try{
- stmt.execute(sql);
- System.out.println("Update Database thành công!!");
- return true;
- }
- catch(Exception e){
- System.out.println("Update Database thất bại!!");
- return false;
- }
- }
- private void CheckDrive(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch(Exception e){
- System.out.println("Không tìm thấy Driver mySql!!");
- }
- }
- private void OpenDB(){
- try{
- String url = ip_DB + "logindatabase?useUnicode=true&characterEncoding=UTF-8";
- conn = DriverManager.getConnection(url, user_DB, pass_DB);
- stmt = conn.createStatement();
- System.out.println("Kết nối thành công Database!!!");
- }
- catch(Exception e){
- System.out.println("Error: " + e.toString() + "** Không thể kết nối Database!!!");
- }
- }
- private void CloseDB(){
- try{
- if(conn != null){
- conn.close();
- conn = null;
- }
- if(stmt != null){
- stmt.close();
- stmt = null;
- }
- System.out.println("Đã đóng Database!!");
- }
- catch(Exception e){
- System.out.println("Không thể đóng Database!!");
- }
- }
- /**
- * 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">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- txtusername = new javax.swing.JTextField();
- txtpassword = new javax.swing.JPasswordField();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255), 20));
- txtusername.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtusernameActionPerformed(evt);
- }
- });
- txtpassword.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtpasswordActionPerformed(evt);
- }
- });
- jLabel1.setIcon(new javax.swing.ImageIcon("E:\\chua_web\\DoAnWeb1\\hinh\\login.png")); // NOI18N
- jLabel2.setIcon(new javax.swing.ImageIcon("E:\\chua_web\\Do_an\\icon\\icons8-spam-50.png")); // NOI18N
- jButton1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- jButton1.setText("SIGNIN");
- jButton2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- jButton2.setText("RESET");
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- }
- ));
- jScrollPane1.setViewportView(jTable1);
- 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(178, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(98, 98, 98)
- .addComponent(txtusername))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addGap(98, 98, 98)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(68, 68, 68)
- .addComponent(jButton2))
- .addComponent(txtpassword, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addComponent(jScrollPane1))
- .addContainerGap(178, Short.MAX_VALUE))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(51, 51, 51)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(txtusername, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(49, 49, 49)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txtpassword, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(35, 35, 35)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(48, 48, 48))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 214, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void txtusernameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtpasswordActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new LoginForm().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- private javax.swing.JPasswordField txtpassword;
- private javax.swing.JTextField txtusername;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement