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

📄 usermanager.java

📁 一个简单的学生信息查询系统
💻 JAVA
字号:
//UserManager.java 


import javax.swing.*; 

import java.awt.*; 
import java.awt.event.*; 

public class UserManager extends JFrame implements ActionListener { 
    private JLabel label_u; 

    private JLabel label_p; 

    private JButton button_add; 

    private JButton button_del; 

    private JPasswordField passwordField; 

    private JTextField textField; 

    private Container con; 

    public UserManager() { 
        super("用户管理"); 
        setSize(214, 143); 
        con = getContentPane(); 
        con.setLayout(null); 

        label_u = new JLabel(); 
        label_u.setText("用户名"); 
        label_u.setBounds(10, 10, 60, 20); 
        con.add(label_u); 

        label_p = new JLabel(); 
        label_p.setText("密码"); 
        label_p.setBounds(10, 46, 60, 20); 
        con.add(label_p); 

        textField = new JTextField(); 
        textField.setBounds(76, 10, 120, 20); 
        con.add(textField); 

        passwordField = new JPasswordField(); 
        passwordField.setBounds(76, 46, 120, 20); 
        passwordField.setEchoChar('*'); 
        con.add(passwordField); 

        button_add = new JButton(); 
        button_add.setText("添加"); 
        button_add.setBounds(29, 77, 60, 23); 
        con.add(button_add); 

        button_del = new JButton(); 
        button_del.setText("删除"); 
        button_del.setBounds(119, 77, 60, 23); 
        con.add(button_del); 

        passwordField.addActionListener(this); 
        button_add.addActionListener(this); 

        button_del.addActionListener(this); 

        // 将窗口置于屏幕中央 
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
        Dimension frameSize = this.getSize(); 
        if (frameSize.height > screenSize.height) { 
            frameSize.height = screenSize.height; 
        } 
        if (frameSize.width > screenSize.width) { 
            frameSize.width = screenSize.width; 
        } 
        setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 
        setResizable(false); 
        setVisible(true); 
    } 

    public void actionPerformed(ActionEvent e) { 
        if (e.getSource() == button_add) { 
            CheckUser add_user = new CheckUser(); 
            // 取得用户输入的用户名 
            String tempUser = textField.getText(); 
            // 取得用户输入的密码 
            char temp[] = passwordField.getPassword(); 
            String tempPass = new String(temp); 
            if (add_user.isExist(tempUser)) { 
                JOptionPane.showMessageDialog(null, "用户已存在", "警告", JOptionPane.WARNING_MESSAGE); 
            } else { 
                if (add_user.adduser(tempUser, tempPass)) { 
                    JOptionPane.showMessageDialog(null, "创建用户成功", "信息", JOptionPane.INFORMATION_MESSAGE); 
                } else { 
                    JOptionPane.showMessageDialog(null, "创建用户失败", "警告", JOptionPane.WARNING_MESSAGE); 
                } 
                setVisible(false); 
            } 

        } else if (e.getSource() == button_del) { 
            CheckUser del_user = new CheckUser(); 
            // 取得用户输入的用户名 
            String tempUser = textField.getText(); 
            if (del_user.isExist(tempUser)) { 
                if (del_user.deluser(tempUser)) { 
                    JOptionPane.showMessageDialog(null, "删除用户成功", "信息", JOptionPane.INFORMATION_MESSAGE); 
                } else { 
                    JOptionPane.showMessageDialog(null, "删除用户失败", "警告", JOptionPane.WARNING_MESSAGE); 
                } 
                textField.setText(""); 
                passwordField.setText(""); 
                setVisible(false); 
            } else { 
                JOptionPane.showMessageDialog(null, "用户不存在", "警告", JOptionPane.WARNING_MESSAGE); 
            } 
        } 
    } 
} 

⌨️ 快捷键说明

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