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

📄 adma.java~21~

📁 Java 聊天程序 有客户端和服务端。
💻 JAVA~21~
📖 第 1 页 / 共 2 页
字号:
package chatserver;

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * <p>Title: 聊天</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: 个人</p>
 *
 * @author Mothz
 * @version 1.0
 */
public class adma
    extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JRadioButton jRadioButton1 = new JRadioButton();
    JRadioButton jRadioButton2 = new JRadioButton();
    JRadioButton jRadioButton3 = new JRadioButton();
    JLabel jLabel5 = new JLabel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    ButtonGroup buttonGroup1 = new ButtonGroup();
    JTextField jTextField1 = new JTextField();
    JPasswordField jPasswordField1 = new JPasswordField();
    JPasswordField jPasswordField2 = new JPasswordField();
    JPasswordField jPasswordField3 = new JPasswordField();
    //定义静态idone 获取登录时获取的管理员ID
    static String idone = null;

    public adma() {
        try {
            this.setIconImage(Toolkit.getDefaultToolkit().createImage(
                "images/1.png"));
            jbInit();
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setSize(400, 300);
        this.setTitle("管理员管理");
        this.setResizable(false);
        getContentPane().setLayout(borderLayout1);
        jRadioButton3.setText("删除帐号");
        jRadioButton3.setBounds(new Rectangle(249, 30, 103, 20));
        jRadioButton3.addActionListener(new adma_jRadioButton3_actionAdapter(this));
        jLabel5.setText("操作类型:");
        jLabel5.setBounds(new Rectangle(26, 11, 64, 15));
        jButton1.setBounds(new Rectangle(80, 213, 75, 20));
        jButton1.setBorder(null);
        jButton1.setIcon(new ImageIcon(
            "images/ok.jpg"));
        jButton1.addActionListener(new adma_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(226, 213, 75, 20));
        jButton2.setIcon(new ImageIcon("images/cancel.jpg"));
        jButton2.addActionListener(new adma_jButton2_actionAdapter(this));
        jRadioButton1.setSelected(true);
        jRadioButton1.addActionListener(new adma_jRadioButton1_actionAdapter(this));
        jTextField1.setBounds(new Rectangle(123, 66, 195, 20));
        jPasswordField1.setBounds(new Rectangle(123, 101, 195, 20));
        jPasswordField2.setBounds(new Rectangle(123, 131, 195, 20));
        jPasswordField3.setBounds(new Rectangle(123, 166, 195, 20));
        jRadioButton2.addActionListener(new adma_jRadioButton2_actionAdapter(this));
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
        jLabel2.setToolTipText("");
        jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel2.setText("密码:");
        jLabel2.setBounds(new Rectangle(42, 103, 56, 15));
        jLabel3.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel3.setText("新密码:");
        jLabel3.setBounds(new Rectangle(42, 133, 56, 15));
        jLabel4.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel4.setText("确认密码:");
        jLabel4.setBounds(new Rectangle(40, 169, 58, 15));
        jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
        jRadioButton1.setText("修改密码");
        jRadioButton1.setBounds(new Rectangle(64, 30, 80, 20));
        jRadioButton2.setText("添加帐号");
        jRadioButton2.setBounds(new Rectangle(155, 30, 77, 20));
        jPanel1.add(jLabel5);
        jPanel1.add(jRadioButton1);
        jPanel1.add(jRadioButton2);
        jPanel1.add(jRadioButton3);
        jPanel1.add(jButton1);
        jPanel1.add(jButton2);
        jPanel1.add(jLabel4);
        jPanel1.add(jLabel2);
        jPanel1.add(jLabel1);
        jPanel1.add(jLabel3);
        jPanel1.add(jTextField1);
        jPanel1.add(jPasswordField1);
        jPanel1.add(jPasswordField2);
        jPanel1.add(jPasswordField3);
        jLabel1.setText("管理帐号:");
        jLabel1.setBounds(new Rectangle(42, 68, 56, 15));
        jPanel1.setLayout(null);
        buttonGroup1.add(jRadioButton1);
        buttonGroup1.add(jRadioButton2);
        buttonGroup1.add(jRadioButton3);

        //默认删除管理选择为不可操作
        jRadioButton3.setEnabled(false);

        /*打开管理员管理窗口时,进行是否为超级管理员查询,
         *是超级管理员则将删除管理员选项设为可操作,若不是
         *则默认为不可操作*/
        //获得Staetment对象
        Statement stmt = linkData.getStatement();
        ResultSet rs = stmt.executeQuery(
            "SELECT * FROM Ad WHERE id='" + idone + "'");
        if (rs.next()) {
            if (rs.getString(5).equals("1")) {
                //删除管理员选择项 设置为可操作
                jRadioButton3.setEnabled(true);
            }
        }

    }

    //选择管理员密码修改
    public void jRadioButton1_actionPerformed(ActionEvent e) {
        jTextField1.setEnabled(true);
        jPasswordField1.setEnabled(true);
        jPasswordField2.setEnabled(true);
        jPasswordField3.setEnabled(true);
    }

    //选择添加管理员
    public void jRadioButton2_actionPerformed(ActionEvent e) {
        jTextField1.setEnabled(true);
        jPasswordField1.setEnabled(false);
        jPasswordField2.setEnabled(true);
        jPasswordField3.setEnabled(true);

    }

    //选择删除管理员
    public void jRadioButton3_actionPerformed(ActionEvent e) {
        jTextField1.setEnabled(true);
        jPasswordField1.setEnabled(true);
        jPasswordField2.setEnabled(false);
        jPasswordField3.setEnabled(false);
    }

    //管理员管理窗口---确定键--处理
    public void jButton1_actionPerformed(ActionEvent e) {
        if (jRadioButton1.isSelected()) {
            //添加管理
            //获取输入的管理员帐号
            String id = jTextField1.getText().trim();
            //获取输入的密码
            char[] oldpas = jPasswordField1.getPassword();
            char[] newpas1 = jPasswordField2.getPassword();
            char[] newpas2 = jPasswordField3.getPassword();
            String old = new String(oldpas);
            String new1 = new String(newpas1);
            String new2 = new String(newpas2);
            if (id.equals("")) {
                JOptionPane.showMessageDialog(null, "帐号不能为空", "警告",
                                              JOptionPane.WARNING_MESSAGE);
            }
            else if (old.equals("")) {
                JOptionPane.showMessageDialog(null, "密码不可为空", "警告",
                                              JOptionPane.WARNING_MESSAGE);
            }
            else if (new1.equals("")) {
                JOptionPane.showMessageDialog(null, "新密码不可为空", "警告",
                                              JOptionPane.WARNING_MESSAGE);
            }
            else if (new1.equals(new2)) {
                //获得Staetment对象
                Statement stmt = linkData.getStatement();
                try {
                    //进行号码查询
                    ResultSet rs = stmt.executeQuery(
                        "SELECT * FROM Ad WHERE id='" + id + "'");
                    //存在则执行修改,不存在则提示
                    if (rs.next()) {
                        try {
                            //执行密码修改
                            stmt.executeUpdate("UPDATE Ad SET Password='" +
                                               new1 + "'" + "WHERE id='" + id +
                                               "'");
                            JOptionPane.showMessageDialog(null, "密码修改成功", "",
                                JOptionPane.INFORMATION_MESSAGE);
                            //输入栏清空
                            jTextField1.setText("");
                            jPasswordField1.setText("");
                            jPasswordField2.setText("");
                            jPasswordField3.setText("");

⌨️ 快捷键说明

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