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

📄 edituser.java

📁 用java实现图书资料管理系统 操作系统:Windows 数据库:Windows Access 数据库 开发平台:NetBeans 开发语言:Java 语言
💻 JAVA
字号:
/*
 * register.java
 *
 * Created on 2007年12月18日, 下午11:12
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Owner
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ButtonGroup;
import java.sql.*;
import java.util.*;
import java.util.Date;

public class edituser extends JPanel implements ActionListener
{
    JButton submit,reset;
    Box basebox,box1,box2,box3,sexbox;
    JTextField id,name,email,phone,address,post;
    JPasswordField password1,password2;
    Checkbox female,male;
    CheckboxGroup sex;
    
    Connection con;
    Statement sql;
    ResultSet rs;
    String s;
    userflag userflag;
    int publisherindex,bookclassindex;
    /** Creates a new instance of register */
    public edituser(userflag userflag) {
        this.userflag=userflag;
        if(userflag.flag==false)
        {
            JOptionPane.showMessageDialog(this,"您还没登录");
            add(new Label("请先登录"),BorderLayout.CENTER);
        }
        else
        {
            id=new JTextField(15);
            id.setEditable(false);
            password1=new JPasswordField(15);
            password2=new JPasswordField(15);
            name=new JTextField(15);
            email=new JTextField(15);
            phone=new JTextField(15);
            address=new JTextField(15);
            post=new JTextField(15);
            sex=new CheckboxGroup();
            female=new Checkbox("女",false,sex);
            male=new Checkbox("男",true,sex);
            submit=new JButton("提交");
            reset=new JButton("重设");
            submit.addActionListener(this);
            reset.addActionListener(this);

            sexbox=Box.createHorizontalBox();
            sexbox.add(male);
            sexbox.add(female);

            box1=Box.createVerticalBox();
            box1.add(new Label("用户名"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("密码"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("再一次输入密码"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("姓名"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("性别"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("电子邮件"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("电话"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("地址"));
            box1.add(Box.createVerticalStrut(8));
            box1.add(new Label("邮编"));
            box1.add(Box.createVerticalStrut(15));
            box1.add(submit);

            box2=Box.createVerticalBox();
            box2.add(Box.createVerticalStrut(8));
            box2.add(id);
            box2.add(Box.createVerticalStrut(8));
            box2.add(password1);
            box2.add(Box.createVerticalStrut(8));
            box2.add(password2);
            box2.add(Box.createVerticalStrut(8));
            box2.add(name);
            box2.add(Box.createVerticalStrut(8));
            box2.add(sexbox);
            box2.add(Box.createVerticalStrut(8));
            box2.add(email);
            box2.add(Box.createVerticalStrut(8));
            box2.add(phone);
            box2.add(Box.createVerticalStrut(8));
            box2.add(address);
            box2.add(Box.createVerticalStrut(8));
            box2.add(post);
            box2.add(Box.createVerticalStrut(15));
            box2.add(reset);

            box3=Box.createHorizontalBox();
            box3.add(box1);
            box3.add(box2);

            basebox=Box.createVerticalBox();
            basebox.add(new Label("请如实填写下列信息:"));
            basebox.add(Box.createVerticalStrut(15));
            basebox.add(box3);


            try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            }
            catch(ClassNotFoundException e2){}
            try
            {
                con=DriverManager.getConnection("jdbc:odbc:sample","std","123");
                sql=con.createStatement();
                s="select * from user where id='"+userflag.id+"'";
                System.out.println(s);
                rs=sql.executeQuery(s);
                rs.next();
                id.setText(rs.getString("id"));
                name.setText(rs.getString("name"));
                email.setText(rs.getString("email"));
                phone.setText(rs.getString("phone"));
                address.setText(rs.getString("address"));
                post.setText(rs.getString("post"));
                if(rs.getString("sex").equals("male"))
                {
                    male.setState(true);
                    female.setState(false);
                }
                else
                {
                    male.setState(false);
                    female.setState(true);
                }
            }
            catch(SQLException e3)
            {
               System.out.println(e3);
            }
            add(basebox);
        }
    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==submit)
        {
            if(id.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"用户名不能为空");
            }
            else  if(password1.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"密码不能为空");
            }
            else  if(password2.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"密码不能为空");
            }
            else if(!password1.getText().equals(password2.getText()))
            {
                JOptionPane.showMessageDialog(this,"密码不一致,请重新输入并验证密码");
                password1.setText(null);
                password2.setText(null);
            }
            else  if(name.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"姓名不能为空");
            }
            else  if(email.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"电子邮箱不能为空");
            }
            else  if(phone.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"电话不能为空");
            }
            else  if(address.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"地址不能为空");
            }
            else  if(post.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this,"邮编不能为空");
            }
            else
            {
                String sexstr;
                if(male.getState()==true)
                    sexstr="male";
                else
                    sexstr="female";
                s="update user set id='"+id.getText()+"',password='"+password1.getText()+"',name='"+name.getText()+"',sex='"+sexstr+"',email='"+email.getText()+"',address='"+address.getText()+"',phone='"+phone.getText()+"',post='"+post.getText()+"' where id='"+id.getText()+"'";
                try
                {
                    sql.executeUpdate(s);
                    JOptionPane.showMessageDialog(this,"用户修改资料成功");
                }
                catch(SQLException e6)
                {
                    System.out.println("e6"+e6);
                }
                
            }
        }
        else if(e.getSource()==reset)
        {
            password1.setText(null);
            password2.setText(null);
            phone.setText(null);
            post.setText(null);
            name.setText(null);
            address.setText(null);
            email.setText(null);
        }
    }
}

⌨️ 快捷键说明

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