⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginframe.java

📁 小区物业管理系统(java版) java swing + access 2003
💻 JAVA
字号:
/* * LoginFrame.java * * Created on 2006年3月17日, 下午8:53 */package login;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;import wymanagesystem.MainFrame;/** * * @author  王治 */public class LoginFrame extends javax.swing.JFrame {     private String name;     private String pwd;    /** Creates new form LoginFrame */    public LoginFrame() {        super("用户登录");        initComponents();        setSize(375,325);        Dimension screen=getToolkit().getScreenSize();        setLocation((screen.width-getSize().width)/2, (screen.height-getSize().height)/2);        try{            String theLook=UIManager.getSystemLookAndFeelClassName();            UIManager.setLookAndFeel(theLook);            SwingUtilities.updateComponentTreeUI(this);        }        catch(Exception e){            System.err.println("异常:"+e);        }    }        /** 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.     */    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents    private void initComponents() {        inputs = new javax.swing.JPanel();        labels = new javax.swing.JPanel();        nameLabel = new javax.swing.JLabel();        pwdLabel = new javax.swing.JLabel();        texts = new javax.swing.JPanel();        id = new javax.swing.JTextField();        password = new javax.swing.JPasswordField();        buttons = new javax.swing.JPanel();        ok = new javax.swing.JButton();        cancel = new javax.swing.JButton();        jPanel5 = new javax.swing.JPanel();        icon = new javax.swing.JLabel();        getContentPane().setLayout(null);        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        setName("\u767b\u5f55");        setResizable(false);        inputs.setLayout(null);        inputs.setBorder(new javax.swing.border.EtchedBorder());        labels.setLayout(null);        nameLabel.setText("\u7528\u6237\u540d\uff1a");        labels.add(nameLabel);        nameLabel.setBounds(30, 20, 60, 20);        pwdLabel.setText("\u5bc6\u7801\uff1a");        labels.add(pwdLabel);        pwdLabel.setBounds(30, 70, 50, 15);        inputs.add(labels);        labels.setBounds(10, 10, 100, 110);        texts.setLayout(null);        id.setToolTipText("\u8f93\u5165\u7528\u6237\u540d");        id.setName("");        texts.add(id);        id.setBounds(10, 20, 140, 20);        password.setToolTipText("\u8bf7\u8f93\u5165\u5bc6\u7801");        password.setNextFocusableComponent(ok);        texts.add(password);        password.setBounds(10, 70, 140, 20);        inputs.add(texts);        texts.setBounds(120, 10, 220, 110);        getContentPane().add(inputs);        inputs.setBounds(10, 70, 350, 130);        buttons.setLayout(null);        buttons.setBorder(new javax.swing.border.EtchedBorder());        ok.setText("\u767b\u5f55");        ok.setToolTipText("\u767b\u5f55");        ok.setNextFocusableComponent(ok);        ok.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                okActionPerformed(evt);            }        });        buttons.add(ok);        ok.setBounds(50, 20, 70, 23);        cancel.setText("\u53d6\u6d88");        cancel.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                cancelActionPerformed(evt);            }        });        buttons.add(cancel);        cancel.setBounds(210, 20, 70, 23);        getContentPane().add(buttons);        buttons.setBounds(10, 210, 350, 60);        jPanel5.setLayout(null);        icon.setFont(new java.awt.Font("华文行楷", 1, 36));        icon.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        icon.setIcon(new javax.swing.ImageIcon("F:\\netbeans\\WyManageSystem\\images\\logo.jpg"));        jPanel5.add(icon);        icon.setBounds(0, 0, 350, 50);        getContentPane().add(jPanel5);        jPanel5.setBounds(10, 10, 350, 50);    }    // </editor-fold>//GEN-END:initComponents    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed// TODO 将在此处添加您的处理代码:登录       name=id.getText().trim();//用户名       pwd=new String(password.getPassword());//用户密码        if(name.equals("")||pwd.equals("")){            JOptionPane.showMessageDialog(this,"用户名或密码不能为空","登录",JOptionPane.INFORMATION_MESSAGE);        }        else{           try{               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动               Connection conn=DriverManager.getConnection("jdbc:odbc:wySystem","admin", "admin");//连接数据库               String sql="select id,password from login where id=?";               PreparedStatement pre=conn.prepareCall(sql);//查询表login的sql语句               pre.clearParameters();               pre.setString(1,name);               ResultSet rs=pre.executeQuery();               if(rs.next()){                   String pass=rs.getString("password").trim();                   if(pwd.regionMatches(0,pass,0,pass.length())){                       this.dispose();                       new MainFrame().setVisible(true);                   }                   else{                        JOptionPane.showMessageDialog(this,"密码不正确","登录",JOptionPane.WARNING_MESSAGE);                   }               }               else{                   JOptionPane.showMessageDialog(this,"用户名不存在","登录",JOptionPane.WARNING_MESSAGE);               }               rs.close();               conn.close();           }           catch(Exception e){               JOptionPane.showMessageDialog(this,"登录异常"+e.toString(),"登录",JOptionPane.WARNING_MESSAGE);           }        }    }//GEN-LAST:event_okActionPerformed    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed        System.exit(0);   //退出登录程序     }//GEN-LAST:event_cancelActionPerformed        /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new LoginFrame().setVisible(true);            }        });    }        // 变量声明 - 不进行修改//GEN-BEGIN:variables    private javax.swing.JPanel buttons;    private javax.swing.JButton cancel;    private javax.swing.JLabel icon;    private javax.swing.JTextField id;    private javax.swing.JPanel inputs;    private javax.swing.JPanel jPanel5;    private javax.swing.JPanel labels;    private javax.swing.JLabel nameLabel;    private javax.swing.JButton ok;    private javax.swing.JPasswordField password;    private javax.swing.JLabel pwdLabel;    private javax.swing.JPanel texts;    // 变量声明结束//GEN-END:variables    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -