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

📄 managerlogon.java

📁 java编写的与SQL数据连接的好例子~~功能很完善,可以做实训直接交
💻 JAVA
字号:
/* * ManagerLogOn.java * * Created on 2008年6月29日, 下午4:40 */package stuMS;import java.awt.*;import javax.swing.*;import javax.swing.text.*;/** * * @author  Administrator */public class ManagerLogOn extends javax.swing.JDialog {    Image icon;    String manager = null;    String password = null;    DigitDocumnet document;    boolean isSucceedLogOn = false;    /** Creates new form ManagerLogOn */    public ManagerLogOn(java.awt.Frame parent, boolean modal) {                super(parent, modal);        icon = Toolkit.getDefaultToolkit().getImage( "icon.gif");        document = new DigitDocumnet();        initComponents();        this.setLocationRelativeTo(parent);    }        /** 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="Generated Code">//GEN-BEGIN:initComponents    private void initComponents() {        jPanel1 = new javax.swing.JPanel();        jLabel1 = new javax.swing.JLabel();        jLabel2 = new javax.swing.JLabel();        managerText = new javax.swing.JTextField();        PasswordField = new javax.swing.JPasswordField();        jPanel2 = new javax.swing.JPanel();        LogOnButton = new javax.swing.JButton();        cancelButton = new javax.swing.JButton();        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);        setIconImage(icon);        jLabel1.setText("用户名:");        jLabel2.setText("密码:");        managerText.setBackground(new java.awt.Color(0, 204, 153));        PasswordField.setBackground(new java.awt.Color(0, 204, 102));        PasswordField.setDocument(document);        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);        jPanel1.setLayout(jPanel1Layout);        jPanel1Layout.setHorizontalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()                .addContainerGap()                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jLabel1)                    .addGroup(jPanel1Layout.createSequentialGroup()                        .addGap(14, 14, 14)                        .addComponent(jLabel2)))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)                    .addComponent(PasswordField)                    .addComponent(managerText, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))                .addContainerGap(20, 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(managerText, 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(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        PasswordField.requestFocus();        LogOnButton.setText("登录");        LogOnButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                LogOnButtonActionPerformed(evt);            }        });        cancelButton.setText("取消");        cancelButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                cancelButtonActionPerformed(evt);            }        });        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);        jPanel2.setLayout(jPanel2Layout);        jPanel2Layout.setHorizontalGroup(            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel2Layout.createSequentialGroup()                .addGap(36, 36, 36)                .addComponent(LogOnButton)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(cancelButton)                .addContainerGap(45, Short.MAX_VALUE))        );        jPanel2Layout.setVerticalGroup(            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel2Layout.createSequentialGroup()                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(LogOnButton)                    .addComponent(cancelButton))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        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)                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jPanel2, 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)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        pack();    }// </editor-fold>//GEN-END:initComponents    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed        // TODO add your handling code here:        this.dispose();}//GEN-LAST:event_cancelButtonActionPerformed    private void LogOnButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LogOnButtonActionPerformed        // TODO add your handling code here:        document.count = 1;        UserBean user = new UserBean();        String [][]userInfo = user.getAllStuInfo();        int length = userInfo.length;        int i = 0;        manager = managerText.getText();        password = String.valueOf(PasswordField.getPassword());        while(i<length)        {            if(userInfo[i][1].equals(manager) && userInfo[i][2].equals(password)){                isSucceedLogOn = true;                break;            }                            i++;        }                if(isSucceedLogOn){            JOptionPane.showMessageDialog(null, "登录成功!");            this.dispose();        }                     else            JOptionPane.showMessageDialog(null, "登录失败:用户名或密码错误", "错误", JOptionPane.ERROR_MESSAGE);    }//GEN-LAST:event_LogOnButtonActionPerformed        /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                ManagerLogOn dialog = new ManagerLogOn(new javax.swing.JFrame(), true);                dialog.addWindowListener(new java.awt.event.WindowAdapter() {                    public void windowClosing(java.awt.event.WindowEvent e) {                        System.exit(0);                    }                });                dialog.setVisible(true);            }        });    }    /**     * 文档类型PlainDocumnet的一个实例,限制密码输入只能是数字或字符     */     class DigitDocumnet extends PlainDocument {        int count = 1;        public void insertString(int offset, String s, AttributeSet a) {            char c = s.charAt(0);            if ((c <= '9' && c >= '0' || c<='z' && c >= 'A') &&count <= 8) {                try {                    super.insertString(offset, s, a);                    count++;                } catch (BadLocationException e) {                }            }        }        public void remove(int offset, int length) {            try {                super.remove(offset, length);                count--;            } catch (BadLocationException e) {            }        }      }     // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton LogOnButton;    private javax.swing.JPasswordField PasswordField;    private javax.swing.JButton cancelButton;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel2;    private javax.swing.JTextField managerText;    // End of variables declaration//GEN-END:variables    }

⌨️ 快捷键说明

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