银行管理系统

 

1.菜单

package contentcl;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
/**
 * Menu是一个 菜单类,也是最为底层的一个类
 * 提供各个功能的按钮
 * 
 * 此类未使用布局, 所以使用坐标固定了各个标签和按钮的位置
 *
 */

public class Menu extends JFrame implements ActionListener{

    JButton jb1, jb2, jb3,jb4,jb5,jb6,jb7, jb8;  //创建按钮
    JLabel jlb1, jlb2, jlb3;   //标签
    public Menu() 
    {
        jb1 = new JButton("查询");
        jb2 = new JButton("存款");
        jb3 = new JButton("取款");
        jb4 = new JButton("转账");
        jb5 = new JButton("改密");
        jb6 = new JButton("开户");
        jb7 = new JButton("退卡");

        jlb1 = new JLabel("知足常乐银行");
        jlb1.setFont(new   java.awt.Font("Dialog",   1,   23)); //设置字体类型, 是否加粗,字号
        jlb2 = new JLabel("欢迎您");
        jlb2.setFont(new   java.awt.Font("Dialog",   1,   20));
        jlb3 = new JLabel("请您选择服务");
        jlb3.setFont(new   java.awt.Font("Dialog",   1,   22));

        jb1.addActionListener(this);   //事件监听
        jb2.addActionListener(this);
        jb3.addActionListener(this);
        jb4.addActionListener(this);
        jb5.addActionListener(this);
        jb6.addActionListener(this);
        jb7.addActionListener(this);this.setTitle("银行管理管理系统");  //设置窗体标题
        this.setSize(450, 500);         //设置窗体大小
        this.setLocation(400, 200);     //设置位置
        this.setLayout(null);           //设置布局,不采用布局

        //设置按钮的位置和大小
        jb1.setBounds( 0,50,90,60);   
        jb2.setBounds( 0,150,90,60);
        jb3.setBounds( 0,250,90,60);
        jb8.setBounds(0,350,90,60);
        jb4.setBounds( 354,50,90,60);
        jb5.setBounds( 354,150,90,60);
        jb6.setBounds( 354,250,90,60);
        jb7.setBounds(354,350,90,60);

        //设置标签的位置和大小
        jlb1.setBounds(150,120,150,50);
        jlb2.setBounds(190,160,150,50);
        jlb3.setBounds(150,250,150,50);

        this.add(jb1);   //加入窗体
        this.add(jb2);
        this.add(jb3);
        this.add(jb4);
        this.add(jb5);
        this.add(jb6);
        this.add(jb7);
        this.add(jb8);
        this.add(jlb1);
        this.add(jlb2);
        this.add(jlb3);

        this.setDefaultCloseOperation(EXIT_ON_CLOSE);  //设置可关闭

        this.setVisible(true);  //设置可见
        this.setResizable(false);   //设置不可拉伸大小
    }


    public void actionPerformed(ActionEvent e) {
  
        if (e.getActionCommand()=="查询")
        {
            //String order = e.getActionCommand();
            new Login(e.getActionCommand());
        }
        else if (e.getActionCommand()=="存款")
        {
            new Login(e.getActionCommand());
        }
        else if (e.getActionCommand()=="取款")
        {
            new Login(e.getActionCommand());
        }
     else if (e.getActionCommand()=="开户")
        {
            new Register();  //跳转开户界面
        }else if (e.getActionCommand()=="退卡")
        {
            System.exit(0);;
        }
    }
}

2.开户

* 此类完成对开户页面的编写, 用户需填写 姓名,身份证号, 账户,密码,开户金额信息
 * 
 * 并且会进行验证操作, 如姓名是否合法(中文), 身份证号是否合法等等
public class Register extends JFrame implements ActionListener{

    JButton jb1, jb2;  //按钮
    JLabel jlb1, jlb2, jlb3,jlb4,jlb5, jlb6;  //标签
    JTextField jtf1,jtf2,jtf3,jtf4, jtf5;   //文本框
    JPasswordField jpf; //密码框
    JPanel jp1,jp2,jp3, jp4,jp5,jp6,jp7;        //面板

    public Register() {
        //按钮
        jb1 = new JButton("确定");
        jb2 = new JButton("重置");
        //设置按钮监听
        jb1.addActionListener(this);
        jb2.addActionListener(this);
        //标签信息

        jlb1 = new JLabel("        姓名");
        jlb2 = new JLabel("身份证号");
        jlb3 = new JLabel("        账号");
        jlb4 = new JLabel("        密码");
        jlb6 = new JLabel("注册信息");
        jlb5 = new JLabel("开户金额");

        jlb6.setFont(new   java.awt.Font("Dialog",   1,   20));   //设置字体类型,加粗,大小为20
        //文本信息
        jtf1 = new JTextField(13);
        jtf2 = new JTextField(13);
        jtf3 = new JTextField(13);
        jtf4 = new JTextField(13);
        jtf5 = new JTextField(13);

        jp1 = new JPanel();
        jp2 = new JPanel();
        jp3 = new JPanel();
        jp4 = new JPanel();
        jp5 = new JPanel();
        jp6 = new JPanel();
        jp7 = new JPanel();
        //将对应信息加入面板中
        jp1.add(jlb1);
        jp1.add(jtf1);

        jp2.add(jlb2);
        jp2.add(jtf2);

        jp3.add(jlb3);
        jp3.add(jtf3);

        jp4.add(jlb4);
        jp4.add(jtf4);

        jp5.add(jlb5);
        jp5.add(jtf5);

        jp6.add(jb1);
        jp6.add(jb2);

        jp7.add(jlb6);

        //将JPane加入JFrame中  
        this.add(jp7);  //先加入提示语

        this.add(jp1);  
        this.add(jp2);  
        this.add(jp3); 
        this.add(jp4);
        this.add(jp5);
        this.add(jp6);

        //设置布局
        this.setTitle("注册信息");
        this.setLayout(new GridLayout(7, 1));
        this.setSize(350, 350);   //设置窗体大小
        this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口

        this.setVisible(true);  //设置可见
        this.setResizable(false);   //设置不可拉伸大小

    }

    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        if (e.getActionCommand()=="确定")
        {
            try {
                register();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
        else if (e.getActionCommand()=="重置")
        {
            clear();
        }

    }
    //验证注册信息,并做处理
    public void register() throws IOException
    {
        //判断信息是否补全
        if (jtf1.getText().isEmpty()||jtf2.getText().isEmpty()||
                jtf3.getText().isEmpty()||jtf4.getText().isEmpty()||jtf5.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null, "信息有空缺,请补全!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        //判断身份证号是否为18位
        else if (jtf2.getText().length()!=18)
        {
            JOptionPane.showMessageDialog(null, "非法身份证号,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        //判断金额是否合法
        else if (!new Check().checkmoney(jtf5.getText()))
        {  
            JOptionPane.showMessageDialog(null, "存入金额不合法!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        //判断姓名是否为全中文
        else if (!new Check().checkname(jtf1.getText()))
        {
            JOptionPane.showMessageDialog(null, "姓名不合法!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        //判断账户名和密码是否包含中文
        else if (new Check().checkcountname(jtf3.getText())||new Check().checkcountname(jtf4.getText()))
        {
            JOptionPane.showMessageDialog(null, "用户名或密码存在中文,不合法!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        //满足要求
        else if (!jtf1.getText().isEmpty()&&!jtf2.getText().isEmpty()&&
                !jtf3.getText().isEmpty()&&!jtf4.getText().isEmpty()&&!jtf5.getText().isEmpty())
        {
            //注册成功, 打包为信息数组传递给UserMessage进行更新操作
            String []message = new String[5]; 
            message[0] = jtf1.getText();   //获取输入的文本信息
            message[1] = jtf2.getText();
            message[2] = jtf3.getText();
            message[3] = jtf4.getText();
            message[4] = jtf5.getText();
            if (!new Check().check2(message[2]))   //调用Check的check方法检测用户是否存在, 如果不存在执行
            {
                new UserMessage().write(message);   //调用UserMseeage的write方法进行写操作, 将信息格式化存入
                JOptionPane.showMessageDialog(null,"注册成功!","提示消息",JOptionPane.WARNING_MESSAGE);
                dispose();  //使窗口消失
            }
            else 
            {
                JOptionPane.showMessageDialog(null,"账号已存在,请重新输入!","提示消息",JOptionPane.WARNING_MESSAGE);
                //dispose();
            }
        }
    }

    //清空账号和密码框
    private void clear() {
        // TODO Auto-generated method stub
        jtf1.setText("");    //设置为空
        jtf2.setText("");  
        jtf3.setText("");  
        jtf4.setText("");  
        jtf5.setText("");  

    }
}

3.登录与查询

public class Login extends JFrame implements ActionListener{

    JButton jb1, jb2, jb3;  //按钮
    JPanel jp1,jp2,jp3, jp4;        //面板
    JTextField jtf;   //文本框
    JLabel jlb1, jlb2, jlb3; //标签
    JPasswordField jpf; //密码框

    String name = "123";   //账号密码
    String pwd = "123"; 
    String order;

    public Login(String order) {
        this.order = order;
        // TODO Auto-generated constructor stub
        jb1 = new JButton("登录");
        jb2 = new JButton("重置");
        //设置按钮监听
        jb1.addActionListener(this);
        jb2.addActionListener(this);

        jp1 = new JPanel();  //创建面板
        jp2 = new JPanel();
        jp3 = new JPanel();

        jlb1 = new JLabel("用户名");  //添加标签
        jlb2 = new JLabel("  密  码");

        jtf = new JTextField(10);   //创建文本框和密码框
        jpf = new JPasswordField(10);

        //加入面板中
        jp1.add(jlb1);
        jp1.add(jtf);

        jp2.add(jlb2);
        jp2.add(jpf);

        jp3.add(jb1);
        jp3.add(jb2);

        //将JPane加入JFrame中  
        this.add(jp1);  
        this.add(jp2);  
        this.add(jp3);  

       //设置布局
        this.setTitle("用户登录");
        this.setLayout(new GridLayout(3,1));
        this.setSize(300, 200);   //设置窗体大小
        this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口

        this.setVisible(true);  //设置可见
        this.setResizable(false);   //设置不可拉伸大小

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand()=="登录")
        {
            try {
                login();
            } catch (HeadlessException | IOException e1) {
                e1.printStackTrace();
            }
        }
        else if(e.getActionCommand()=="重置")  
        {  
             clear();  
        }
    }
    //清空账号和密码框
    private void clear() {
        jtf.setText("");    //设置为空
        jpf.setText("");  

    }

    //验证登录信息,并做处理
    public void login() throws HeadlessException, IOException
    {
        //判断账户名和密码是否包含中文
        if (new Check().checkcountname(jtf.getText())||new Check().checkcountname(jpf.getText()))
        {
            JOptionPane.showMessageDialog(null, "用户名或密码存在中文,不合法!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null, "账号密码为空,请输入!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        else if (jtf.getText().isEmpty()) 
        {
            JOptionPane.showMessageDialog(null, "账号为空,请输入!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        else if (jpf.getText().isEmpty()) 
        {
            JOptionPane.showMessageDialog(null, "密码为空,请输入!","消息提示",JOptionPane.WARNING_MESSAGE);

        }
        else if (new Check().check1(jtf.getText(),jpf.getText()))
        {
            JOptionPane.showMessageDialog(null,"登录成功!","提示消息",JOptionPane.WARNING_MESSAGE);
            //dispose();  //使文原窗体消失
            if (order.equals("查询"))
            {
                new Inquiry(jtf.getText()); //跳转到登录个人信息选项界面
                dispose();
            }
            if (order.equals("存款"))
            {
                new SaveMoney(jtf.getText());
                dispose();
            }
            if (order.equals("取款"))
            {
                new DrawMoney(jtf.getText());
                dispose();
            }
            if (order.equals("改密"))
            {
                new Modify(jtf.getText());
                dispose();
            }
            if (order.equals("转账"))
            {
                new Transfer(jtf.getText());
                dispose();
            }

        }
        else
        {
            JOptionPane.showMessageDialog(null, "账号密码错误请重新输入!","消息提示",JOptionPane.ERROR_MESSAGE);
            clear();  //调用清除函数
        }
    }
}
* 此类时对用户信息查询的编写,  我们将查询出用户的姓名身份证号和余额
public class Inquiry extends JFrame implements ActionListener{

    JLabel jlb1, jlb2, jlb3;  //标签
    JTextField jtf1,jtf2,jtf3;   //文本框
    JPasswordField jpf; //密码框
    JPanel jp1,jp2,jp3;     //面板

    public Inquiry(String countname) throws IOException {
        //标签信息

        jlb1 = new JLabel("        姓名");
        jlb2 = new JLabel("身份证号");
        jlb3 = new JLabel("        余额");

        jtf1 = new JTextField(13);
        jtf2 = new JTextField(13);
        jtf3 = new JTextField(13);

        jp1 = new JPanel();
        jp2 = new JPanel();
        jp3 = new JPanel();

        jp1.add(jlb1);
        jp1.add(jtf1);
        jp2.add(jlb2);
        jp2.add(jtf2);
        jp3.add(jlb3);
        jp3.add(jtf3);

        //设置布局
        this.setTitle("查询");
        this.setLayout(null);   //采用空布局

        jp1.setBounds(-10, 40, 300 ,50);  
        jp2.setBounds(-10, 110, 300 ,50);
        jp3.setBounds(-10, 180, 300 ,50);

        //将JPane加入JFrame中  
        this.add(jp1);  
        this.add(jp2);  
        this.add(jp3); 

        this.setSize(300, 300);   //设置窗体大小
        this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口

        this.setVisible(true);  //设置可见
        this.setResizable(false);   //设置不可拉伸大小

        String []message = new UserMessage().read(countname);

        //将姓名的第一个字变为*
        message[0] ="*"+message[0].substring(1,message[0].length());
        //将身份证号第6到12位变成*
        message[1] =message[1].substring(0,6)+"*******"+message[1].substring(13,message[1].length());


        jtf1.setText(message[0]);   //将信息显示在文本框中
        jtf2.setText(message[1]);
        jtf3.setText(message[4]);
    }
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub

    }
}

4.存取款

public class SaveMoney extends JFrame implements ActionListener{
    String countname;
    JButton jb1, jb2, jb3;  //按钮
    JLabel jlb1, jlb2, jlb3; //标签
    JTextArea jta1,jta2;

    public SaveMoney(String countname) {
        this.countname = countname;

        jb1 = new JButton("确定");
        jb2 = new JButton("重置");
        //设置按钮监听
        jb1.addActionListener(this);
        jb2.addActionListener(this);


        jlb1 = new JLabel("请输入存入金额:");  //添加标签

        //创建文本框
         jta1 = new JTextArea();
         jta2 = new JTextArea();


       //设置布局
        this.setTitle("存钱");
        this.setLayout(null);
        this.setSize(300, 300); 

        //存入标签和文本框
        jlb1.setBounds(5, 20, 200, 20);
        jta1.setBounds(20, 50, 250, 50);
        jta1.setFont(new   java.awt.Font("Dialog",   0,   15)); //设置字体为字形, 不加粗,15号字体

        //确定和重置按钮
        jb1.setBounds(60, 120, 62, 28);
        jb2.setBounds(160, 120, 62, 28);

        //显示结果文本框
        //jlb1.setBounds(5, 20, 200, 20);
        jta2.setBounds(20, 160, 300, 50);
        jta2.setFont(new   java.awt.Font("Dialog",   1,   15));
        //jta2.setText("您的余额为:\n ");

       this.add(jlb1);
       this.add(jta1);
       this.add(jb1);
       this.add(jb2);
       this.add(jta2);

       this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  
       this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口

       this.setVisible(true);  //设置可见
       this.setResizable(false);    //设置不可拉伸大小

    }

    //清空账号和密码框
        private void clear() 
        {
            jta1.setText("");    //设置为空
            jta2.setText("");  

        }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand()=="确定")
        {

            try {
                savemoney();   //将存入金额传入判断是否合法
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        else if (e.getActionCommand()=="重置")
        {
            clear();
        }

    }

    private void savemoney() throws IOException {
        if (jta1.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null, "金额为空,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        else if(new Check().checkmoney(jta1.getText()))  //验证金额是否合法
        {
            //将账户和金额传入, 进行存储
            String nowmoney = new UserMessage().updatemoney(countname,Integer.parseInt(jta1.getText()));
            if (!nowmoney.equals("负数"))
            {
                jta2.setText("您的余额为:\n "+nowmoney);
                jta1.setText("");
            }
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "存入金额不合法!","消息提示",JOptionPane.WARNING_MESSAGE);
        }

    }
}


新增功能为:转账与改密。

public class Modify extends JFrame implements ActionListener{
    JButton jb1, jb2, jb3;  //按钮
    JPanel jp1,jp2,jp3, jp4;        //面板
    JPasswordField jtf1,jtf2;   //文本框
    JLabel jlb1, jlb2, jlb3; //标签

    String name = "123";   //账号密码
    String pwd = "123"; 
    String countname;

    public Modify(String countname) {
        this.countname = countname;
        jb1 = new JButton("确定");
        jb2 = new JButton("重置");
        //设置按钮监听
        jb1.addActionListener(this);
        jb2.addActionListener(this);

        jp1 = new JPanel();  //创建面板
        jp2 = new JPanel();
        jp3 = new JPanel();

        jlb1 = new JLabel("    新密码");  //添加标签
        jlb2 = new JLabel("重复密码");

        jtf1 = new JPasswordField(10);  //创建文本框
        jtf2 = new JPasswordField(10);

        //加入面板中
        jp1.add(jlb1);
        jp1.add(jtf1);

        jp2.add(jlb2);
        jp2.add(jtf2);

        jp3.add(jb1);
        jp3.add(jb2);

        //将JPane加入JFrame中  
        this.add(jp1);  
        this.add(jp2);  
        this.add(jp3);  

       //设置布局
        this.setTitle("用户登录");
        this.setLayout(new GridLayout(3,1));  //利用网格布局
        this.setSize(300, 200);   //设置窗体大小
        this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口

        this.setVisible(true);  //设置可见
        this.setResizable(false);   //设置不可拉伸大小

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand()=="确定")
        {

            try {
                modify();  //进行信息核对
            } catch (IOException e1) {
                e1.printStackTrace();
            }  
        }
        else if (e.getActionCommand()=="重置")
        {
            clear();   //清楚信息
        }

    }

    private void modify() throws IOException {
        if (jtf1.getText().isEmpty()||jtf2.getText().isEmpty())  //判断信息是否为空
        {
            JOptionPane.showMessageDialog(null, "信息未填写完成!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        else if (jtf1.getText().equals(jtf2.getText()))
        {
            new UserMessage().updatepwd(countname, jtf1.getText());   //调用UserMessage的updatepwd函数更新密码
            JOptionPane.showMessageDialog(null, "修改成功!","消息提示",JOptionPane.WARNING_MESSAGE);
            dispose();
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "2次密码不一致,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);
            clear();
        }

    }
    //清空密码框
    private void clear() 
    {

        jtf1.setText("");    //设置为空
        jtf2.setText("");  
    }

}
public class DrawMoney extends JFrame implements ActionListener{
    String countname;
    JButton jb1, jb2, jb3;  //按钮
    JLabel jlb1, jlb2, jlb3; //标签
    JTextArea jta1,jta2; public DrawMoney(String countname) {
        this.countname = countname; // TODO Auto-generated constructor stub
        jb1 = new JButton("确定");
        jb2 = new JButton("重置");
        //设置按钮监听
        jb1.addActionListener(this);
        jb2.addActionListener(this);        jlb1 = new JLabel("请输入取出金额:");  //添加标签
 //创建文本框
         jta1 = new JTextArea();
         jta2 = new JTextArea();       //设置布局
        this.setTitle("取钱");
        this.setLayout(null);
        this.setSize(300, 300);  //存入标签和文本框
        jlb1.setBounds(5, 20, 200, 20);
        jta1.setBounds(20, 50, 250, 50);
        jta1.setFont(new   java.awt.Font("Dialog",   0,   15)); //确定和重置按钮
        jb1.setBounds(60, 120, 62, 28);
        jb2.setBounds(160, 120, 62, 28); //显示结果文本框
        //jlb1.setBounds(5, 20, 200, 20);
        jta2.setBounds(20, 160, 300, 50);
        jta2.setFont(new   java.awt.Font("Dialog",   1,   15));
        //jta2.setText("您的余额为:\n "); this.add(jlb1);
       this.add(jta1);
       this.add(jb1);
       this.add(jb2);
       this.add(jta2); this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示) 
       this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口 this.setVisible(true); //设置可见
       this.setResizable(false);    //设置不可拉伸大小}
 //清空账号和密码框
        private void clear() 
        {
            jta1.setText("");    //设置为空
            jta2.setText("");  }
 public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand()=="确定")
        { try {
                drawmoney();   //将存入金额传入判断是否合法
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        else if (e.getActionCommand()=="重置")
        {
            clear();
        }}
 private void drawmoney() throws IOException {
        if (jta1.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null, "金额为空,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        else if(new Check().checkmoney(jta1.getText()))
        {
            String nowmoney = new UserMessage().updatemoney(countname,-Integer.parseInt(jta1.getText()));
            if (!nowmoney.equals("负数"))
            {
                jta2.setText("您的余额为:\n "+nowmoney);
                jta1.setText("");
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "余额不足请重新输入:","消息提示",JOptionPane.WARNING_MESSAGE);
                clear();
            }
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "存入金额不合法!","消息提示",JOptionPane.WARNING_MESSAGE);
        }    }
}

新增功能为:转账与改密。

public class Modify extends JFrame implements ActionListener{
    JButton jb1, jb2, jb3;  //按钮
    JPanel jp1,jp2,jp3, jp4;        //面板
    JPasswordField jtf1,jtf2;   //文本框
    JLabel jlb1, jlb2, jlb3; //标签 String name = "123"; //账号密码
    String pwd = "123"; 
    String countname; public Modify(String countname) {
        this.countname = countname;
        jb1 = new JButton("确定");
        jb2 = new JButton("重置");
        //设置按钮监听
        jb1.addActionListener(this);
        jb2.addActionListener(this); jp1 = new JPanel(); //创建面板
        jp2 = new JPanel();
        jp3 = new JPanel(); jlb1 = new JLabel(" 新密码"); //添加标签
        jlb2 = new JLabel("重复密码"); jtf1 = new JPasswordField(10); //创建文本框
        jtf2 = new JPasswordField(10); //加入面板中
        jp1.add(jlb1);
        jp1.add(jtf1); jp2.add(jlb2);
        jp2.add(jtf2); jp3.add(jb1);
        jp3.add(jb2); //将JPane加入JFrame中 
        this.add(jp1);  
        this.add(jp2);  
        this.add(jp3);   //设置布局
        this.setTitle("用户登录");
        this.setLayout(new GridLayout(3,1));  //利用网格布局
        this.setSize(300, 200);   //设置窗体大小
        this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口 this.setVisible(true); //设置可见
        this.setResizable(false);   //设置不可拉伸大小}
 public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand()=="确定")
        { try {
                modify();  //进行信息核对
            } catch (IOException e1) {
                e1.printStackTrace();
            }  
        }
        else if (e.getActionCommand()=="重置")
        {
            clear();   //清楚信息
        }}
 private void modify() throws IOException {
        if (jtf1.getText().isEmpty()||jtf2.getText().isEmpty())  //判断信息是否为空
        {
            JOptionPane.showMessageDialog(null, "信息未填写完成!","消息提示",JOptionPane.WARNING_MESSAGE);
        }
        else if (jtf1.getText().equals(jtf2.getText()))
        {
            new UserMessage().updatepwd(countname, jtf1.getText());   //调用UserMessage的updatepwd函数更新密码
            JOptionPane.showMessageDialog(null, "修改成功!","消息提示",JOptionPane.WARNING_MESSAGE);
            dispose();
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "2次密码不一致,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);
            clear();
        } }
    //清空密码框
    private void clear() 
    {
        jtf1.setText("");    //设置为空
        jtf2.setText("");  
    }}