Toggle Theme Editor
Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Charcoal

Xem dùm mình cái LoginForm với??!

Discussion in 'Xây dựng ứng dụng server-client desktop' started by JackieChan, 25/4/11.

  1. JackieChan

    JackieChan New Member

    Các bạn xem dùm mình cái LoginForm này với, không biết lỗii gì mà kết nối csdl MySQL rồi (sử dụng Navicat for MySQL để giao tiếp với MySQL) mà đăng nhập nó không được?
    Code:
    
    package tieuluan.ui.form;
    
    import tieuluan.tool.Dialog;
    import tieuluan.User;
    import tieuluan.db.DBUser;
    
    /**
     *
     * @author 
     */
    public class LoginForm extends javax.swing.JFrame {
        private static LoginForm instance;
    
        /** Creates new form LoginForm */
        public LoginForm() {
            initComponents();        
            this.jtfusername.setText("");
            this.jpwpassword.setText("");
        }
    
        public static LoginForm getInstance(){
            if(instance == null)
                return instance = new LoginForm();
            else return instance;
        }
    
        /** 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() {
    
            jScrollPane1 = new javax.swing.JScrollPane();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jtfusername = new javax.swing.JTextField();
            jpwpassword = new javax.swing.JPasswordField();
            jLabel4 = new javax.swing.JLabel();
            jbdangnhap = new javax.swing.JButton();
            jbthoat = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Đăng nhập");
            setBackground(new java.awt.Color(153, 153, 255));
            setBounds(new java.awt.Rectangle(300, 200, 0, 0));
            setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            setFont(new java.awt.Font("Tahoma", 1, 12));
            setName(null);
    
            jLabel1.setBackground(new java.awt.Color(51, 51, 0));
            jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18));
            jLabel1.setForeground(new java.awt.Color(0, 0, 102));
            jLabel1.setText("          HỆ THỐNG QUẢN LÝ ĐĂNG KÝ BUỔI THỰC HÀNH");
            jScrollPane1.setViewportView(jLabel1);
    
            jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
            jLabel2.setText("Tài khoản");
    
            jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
            jLabel3.setText("Mật khẩu");
    
            jtfusername.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
    
            jpwpassword.setFont(new java.awt.Font("Tahoma", 0, 12));
    
            jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tieuluan/image/login_icon_1.png"))); // NOI18N
    
            jbdangnhap.setFont(new java.awt.Font("Tahoma", 1, 12));
            jbdangnhap.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tieuluan/image/icon_tick.gif"))); // NOI18N
            jbdangnhap.setText("Đăng Nhập");
            jbdangnhap.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jbdangnhapActionPerformed(evt);
                }
            });
    
            jbthoat.setFont(new java.awt.Font("Tahoma", 1, 12));
            jbthoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tieuluan/image/delete3.jpg"))); // NOI18N
            jbthoat.setText("Thoát");
            jbthoat.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jbthoatActionPerformed(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()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(31, 31, 31)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jpwpassword)
                                .addComponent(jtfusername, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jbdangnhap)
                            .addGap(18, 18, 18)
                            .addComponent(jbthoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(31, 31, 31)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(45, 45, 45)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(jtfusername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(jpwpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jbthoat)
                                .addComponent(jbdangnhap))
                            .addGap(43, 43, 43))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void jbdangnhapActionPerformed(java.awt.event.ActionEvent evt) {                                           
            String username = jtfusername.getText();
            String password = jpwpassword.getText();
            if (username.equals("") || username == null) {
                Dialog.getInstance().showDialog("Chưa nhập tài khoản!", "Lỗi", 1);
                return;
            }
            if (password.equals("") || password == null) {
                Dialog.getInstance().showDialog("Chưa nhập mật khẩu!", "Lỗi", 1);
                return;
            }
            User user = new User();
            user.setId(username);
            user.setPass(password);
            int result = user.login(user);
            if (result == DBUser.ISADMIN) {
               AdminForm af = new AdminForm(user);
                af.show();
                this.dispose();
            } else if (result == DBUser.ISTEACHER) {
                TeacherForm tf = new TeacherForm(user);
                tf.show();
                this.dispose();
            } else if (result == DBUser.ISSTUDENT) {
               StudentForm sf = new StudentForm(user);
                sf.show();
                this.dispose();
            } else if (result == DBUser.ISNOTFOUND) {
                Dialog.getInstance().showDialog("Tài khoản không tồn tại, vui lòng thử lại!", "Lỗi", Dialog.ISERROR_MESSAGE);
            } else if (result == DBUser.ISWORNGPASS) {
                Dialog.getInstance().showDialog("Mật khẩu không đúng!", "Lỗi", Dialog.ISERROR_MESSAGE);
            }
        }                                          
    
        private void jbthoatActionPerformed(java.awt.event.ActionEvent evt) {                                        
            System.exit(0);
        }                                       
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new LoginForm().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JButton jbdangnhap;
        private javax.swing.JButton jbthoat;
        private javax.swing.JPasswordField jpwpassword;
        private javax.swing.JTextField jtfusername;
        // End of variables declaration                   
    
    }
    
    Nếu cần thì mình post cả project lên cũng được. Mọi người xem dùm mình với.
     
  2. JackieChan

    JackieChan New Member

    Ðề: Xem dùm mình cái LoginForm với??!

    Trôi nhanh quá:D
     
  3. ganewbie

    ganewbie New Member

    bác nào cho e xin full cái project đăng nhập kết nối với mysql với ạ... em newbie
     
  4. badboy3283

    badboy3283 Active Member

    Nói chung là bó
     
  5. JackV

    JackV Administrator Staff Member

    Đi học hay đi xin vậy bạn?
     

Chia sẻ trang này

Loading...