图书馆管理系统

1.系统界面文件:LibraryUI.java

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

public class LibraryUI{

    //主方法
    public static void main(String[] args){
        LibraryUI ui = new LibraryUI();
        ui.initbo();
        ui.initFrame();
        ui.showLogin();

    }

    //初始化业务对象
    public LibraryBO bo = null;
    public void initbo(){
        bo = new LibraryBO();
    }

    //初始化主窗口
    public int width = 800;
    public int height = 650;
    public JFrame jframe = null;
    public JPanel frontLayer = null;
    public JPanel back_panel = null;
    public JPanel backLayer = null;
    public JLabel back_label = null;
    public CardLayout cardLayout = null;
    public JLayeredPane layeredPane = null;
    public void initFrame(){
        jframe = new JFrame("图书馆管理系统");
        layeredPane = new JLayeredPane();
        layeredPane.setPreferredSize(new Dimension(width,height));
        jframe.add(layeredPane);
        jframe.setResizable(false);
        jframe.pack();
        jframe.setVisible(true);
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        backLayer = new JPanel();
        ((FlowLayout)backLayer.getLayout()).setHgap(0);
        ((FlowLayout)backLayer.getLayout()).setVgap(0);
        backLayer.setSize(width,height);
        backLayer.setLocation(0,0);
        JLabel bg = new JLabel(new ImageIcon("p3.jpg"));
        backLayer.add(bg);
        layeredPane.add(backLayer, new Integer(0));

        back_panel = new JPanel();
        back_panel.setOpaque(false);
        back_panel.setSize(400,40);
        back_panel.setLocation(200,100);
        back_label = new JLabel("图书馆管理系统");
        back_label.setForeground(Color.WHITE);
        back_label.setFont(new Font("宋体",Font.BOLD,30));
        back_panel.add(back_label);
        layeredPane.add(back_panel,new Integer(1));

        frontLayer = new JPanel();
        cardLayout = new CardLayout(0,0);
        frontLayer.setLayout(cardLayout);
        frontLayer.setOpaque(false);
        frontLayer.setSize(width,height);
        frontLayer.setLocation(0,0);
        layeredPane.add(frontLayer,new Integer(1));


    }

    //登录界面
    public JPanel loginPane = null;
    public JPasswordField passInput = null;
    public JLabel loginTipsLabel = null;
    public void showLogin(){
        if(loginPane == null){
            loginPane = new JPanel();
            loginPane.setOpaque(false);

            Box loginBox = Box.createVerticalBox();
            loginBox.add(Box.createVerticalStrut(180));

            JPanel deng_panel = new JPanel();
            deng_panel.setOpaque(false);
            JLabel deng_label = new JLabel("管理员登录");
            deng_label.setForeground(Color.WHITE);
            deng_label.setFont(new Font("宋体",Font.PLAIN,25));
            deng_panel.add(deng_label);
            loginBox.add(deng_panel);

            loginBox.add(Box.createVerticalStrut(30));

            JPanel pass_panel = new JPanel();
            pass_panel.setOpaque(false);
            JLabel pass_label = new JLabel("密码:");
            pass_label.setForeground(Color.WHITE);
            pass_label.setFont(new Font("宋体",Font.PLAIN,25));
            pass_panel.add(pass_label);
            passInput = new JPasswordField(10);
            passInput.setFont(new Font("宋体",Font.PLAIN,25));
            pass_panel.add(passInput);
            loginBox.add(pass_panel);

            loginBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton deng_btn = new JButton("登 录");
            deng_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(deng_btn);
            loginBox.add(btn_panel);

            loginBox.add(Box.createVerticalStrut(10));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            loginTipsLabel = new JLabel("");
            loginTipsLabel.setForeground(new Color(238,32,32));
            loginTipsLabel.setFont(new Font("宋体",Font.PLAIN,20));
            tips_panel.add(loginTipsLabel);
            loginBox.add(tips_panel);

            loginPane.add(loginBox);

            frontLayer.add("loginPane",loginPane);
            cardLayout.show(frontLayer,"loginPane");
            frontLayer.validate();
            passInput.requestFocus();

            deng_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    String pass_str = new String(passInput.getPassword());
                    if("".equals(pass_str)){
                        loginTipsLabel.setText("密码不能为空!");
                        passInput.requestFocus();
                    }else{
                        int login_rtn = bo.login(pass_str);
                        if(login_rtn!=-1){
                            loginTipsLabel.setText("密码错误!");
                            passInput.setText("");
                            passInput.requestFocus();
                        }else{
                            showMenu();
                        }
                    }
                }
            });
        }else{
            cardLayout.show(frontLayer,"loginPane");
            passInput.setText("");
            loginTipsLabel.setText("");
            passInput.requestFocus();
        }
    }

    //主菜单界面
    public JPanel menuPane = null;
    public void showMenu(){
        if(menuPane == null){
            menuPane = new JPanel();
            menuPane.setOpaque(false);
            menuPane.setLayout(new BorderLayout());

            Box leftBox = Box.createVerticalBox();
            menuPane.add(leftBox,BorderLayout.WEST);
            leftBox.add(Box.createVerticalStrut(200));
            JButton add_btn = new JButton("新增图书");
            add_btn.setFont(new Font("宋体",Font.PLAIN,25));
            leftBox.add(add_btn);

            leftBox.add(Box.createVerticalStrut(30));

            JButton jie_btn = new JButton("借书");
            jie_btn.setFont(new Font("宋体",Font.PLAIN,25));
            leftBox.add(jie_btn);

            leftBox.add(Box.createVerticalStrut(30));

            JButton huan_btn = new JButton("还书");
            huan_btn.setFont(new Font("宋体",Font.PLAIN,25));
            leftBox.add(huan_btn);

            Box rightBox = Box.createVerticalBox();
            menuPane.add(rightBox,BorderLayout.EAST);
            rightBox.add(Box.createVerticalStrut(200));
            JButton cha_btn = new JButton("图书信息查询【修改/删除】");
            cha_btn.setAlignmentX(Component.RIGHT_ALIGNMENT);
            cha_btn.setFont(new Font("宋体",Font.PLAIN,25));
            rightBox.add(cha_btn);

            rightBox.add(Box.createVerticalStrut(30));

            JButton xue_btn = new JButton("学员借书情况查询");
            xue_btn.setFont(new Font("宋体",Font.PLAIN,25));
            xue_btn.setAlignmentX(Component.RIGHT_ALIGNMENT);
            rightBox.add(xue_btn);

            rightBox.add(Box.createVerticalStrut(30));

            JButton quit_btn = new JButton("退出");
            quit_btn.setFont(new Font("宋体",Font.PLAIN,25));
            quit_btn.setAlignmentX(Component.RIGHT_ALIGNMENT);
            rightBox.add(quit_btn);

            frontLayer.add("menuPane",menuPane);
            cardLayout.show(frontLayer,"menuPane");
            frontLayer.validate();

            add_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showAdd();
                }
            });

            jie_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showBorrow();
                }
            });

            huan_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showBack();
                }
            });

            cha_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showUpdate();
                }
            });

            xue_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showCheck();
                }
            });

            quit_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showLogin();
                }
            });

            }else{
                cardLayout.show(frontLayer,"menuPane");
            }   
    }

    //新增图书
    public JPanel addPane = null;
    public JTextField bookInput = null;
    public JTextField authorInput = null;
    public JTextField fromInput = null;
    public JLabel addTipsLabel = null;
    public String book_str;
    public String author_str;
    public String from_str;
    public void showAdd(){
        if( addPane == null){
            addPane = new JPanel();
            addPane.setOpaque(false);

            Box addBox = Box.createVerticalBox();
            addBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("新增图书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            addBox.add(title_panel);

            addBox.add(Box.createVerticalStrut(30));

            JPanel book_panel = new JPanel();
            book_panel.setOpaque(false);
            JLabel book_label = new JLabel("书名:");
            book_label.setForeground(Color.WHITE);
            book_label.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(book_label);
            bookInput = new JTextField(15);
            bookInput.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(bookInput);
            addBox.add(book_panel);

            addBox.add(Box.createVerticalStrut(30));

            JPanel author_panel = new JPanel();
            author_panel.setOpaque(false);
            JLabel author_label = new JLabel("作者:");
            author_label.setForeground(Color.WHITE);
            author_label.setFont(new Font("宋体",Font.PLAIN,25));
            author_panel.add(author_label);
            authorInput = new JTextField(15);
            authorInput.setFont(new Font("宋体",Font.PLAIN,25));
            author_panel.add(authorInput);
            addBox.add(author_panel);

            addBox.add(Box.createVerticalStrut(30));

            JPanel from_panel = new JPanel();
            from_panel.setOpaque(false);
            JLabel from_label = new JLabel("出版社:");
            from_label.setForeground(Color.WHITE);
            from_label.setFont(new Font("宋体",Font.PLAIN,25));
            from_panel.add(from_label);
            fromInput = new JTextField(15);
            fromInput.setFont(new Font("宋体",Font.PLAIN,25));
            from_panel.add(fromInput);
            addBox.add(from_panel);

            addBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton confirm_btn = new JButton("确认新增");
            confirm_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(confirm_btn);
            JButton return_btn = new JButton("返回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            addBox.add(btn_panel);

            addBox.add(Box.createVerticalStrut(10));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            addTipsLabel = new JLabel("");
            addTipsLabel.setForeground(new Color(238,32,32));
            addTipsLabel.setFont(new Font("宋体",Font.PLAIN,20));
            tips_panel.add(addTipsLabel);
            addBox.add(tips_panel);

            addPane.add(addBox);

            frontLayer.add("addPane",addPane);
            cardLayout.show(frontLayer,"addPane");
            frontLayer.validate();
            bookInput.requestFocus();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });

            confirm_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    book_str = bookInput.getText();
                    author_str = authorInput.getText();
                    from_str = fromInput.getText();

                    if("".equals(book_str)){
                        addTipsLabel.setText("书名不能为空!");
                        bookInput.requestFocus();
                    }else if("".equals(author_str)){
                        addTipsLabel.setText("作者不能为空!");
                        authorInput.requestFocus();
                    }else if("".equals(from_str)){
                        addTipsLabel.setText("出版社不能为空!");
                        fromInput.requestFocus();
                    }else{
                        showAddSuccess();
                    }
                }
            });
        }else{
            cardLayout.show(frontLayer,"addPane");
            bookInput.setText("");
            authorInput.setText("");
            fromInput.setText("");
            addTipsLabel.setText("");
            bookInput.requestFocus();
        }
    }

    //新增图书成功
    public JPanel addSuccessPane = null;
    public void showAddSuccess(){
        bo.add(book_str,author_str,from_str);
        if(addSuccessPane == null){
            addSuccessPane = new JPanel();
            addSuccessPane.setOpaque(false);

            Box addSuccessBox = Box.createVerticalBox();
            addSuccessBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("新增图书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            addSuccessBox.add(title_panel);

            addSuccessBox.add(Box.createVerticalStrut(30));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            JLabel tips_label = new JLabel("新增图书成功!");
            tips_label.setForeground(Color.WHITE);
            tips_label.setFont(new Font("宋体",Font.PLAIN,25));
            tips_panel.add(tips_label);
            addSuccessBox.add(tips_panel);

            addSuccessBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            addSuccessBox.add(btn_panel);

            addSuccessPane.add(addSuccessBox);

            frontLayer.add("addSuccessPane",addSuccessPane);
            cardLayout.show(frontLayer,"addSuccessPane");
            frontLayer.validate();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });
        }else{
            cardLayout.show(frontLayer,"addSuccessPane");
        }   
    }


    //图书信息查询
    public JPanel updatePane = null;
    public JTextField bookNameInput = null;
    public JLabel updateTipsLabel = null;
    public int index;
    public void showUpdate(){
        if(updatePane == null){
            updatePane = new JPanel();
            updatePane.setOpaque(false);

            Box updateBox = Box.createVerticalBox();
            updateBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("图书信息查询");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            updateBox.add(title_panel);

            updateBox.add(Box.createVerticalStrut(30));

            JPanel book_panel = new JPanel();
            book_panel.setOpaque(false);
            JLabel book_label = new JLabel("书名:");
            book_label.setForeground(Color.WHITE);
            book_label.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(book_label);
            bookNameInput = new JTextField(15);
            bookNameInput.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(bookNameInput);
            updateBox.add(book_panel);

            updateBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton confirm_btn = new JButton("确 认");
            confirm_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(confirm_btn);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            updateBox.add(btn_panel);

            updateBox.add(Box.createVerticalStrut(10));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            updateTipsLabel = new JLabel("");
            updateTipsLabel.setForeground(new Color(238,32,32));
            updateTipsLabel.setFont(new Font("宋体",Font.PLAIN,20));
            tips_panel.add(updateTipsLabel);
            updateBox.add(tips_panel);
            updatePane.add(updateBox);

            frontLayer.add("updatePane",updatePane);
            cardLayout.show(frontLayer,"updatePane");
            frontLayer.validate();
            bookNameInput.requestFocus();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });

            confirm_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    String bookName_str = bookNameInput.getText();
                    if("".equals(bookName_str)){
                        updateTipsLabel.setText("书名不能为空!");
                        bookNameInput.requestFocus();
                    }else{
                        index = bo.update(bookName_str);
                        if(index!=-1){
                            showUpdate1();
                        }else{
                            updateTipsLabel.setText("没有此书!");
                            bookNameInput.requestFocus();
                        }
                    }
                }
            });
        }else{
            cardLayout.show(frontLayer,"updatePane");
            bookNameInput.setText("");
            updateTipsLabel.setText("");
            bookNameInput.requestFocus();
        }
    }

    //进入图书信息界面
    public JPanel updatePane1 = null;
    public void showUpdate1(){
            updatePane1 = new JPanel();
            updatePane1.setOpaque(false);
            Box updateBox1 = Box.createVerticalBox();
            updateBox1.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("图书信息查询");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            updateBox1.add(title_panel);

            updateBox1.add(Box.createVerticalStrut(30)); 

            JPanel book_panel = new JPanel();
            book_panel.setOpaque(false);
            JLabel book_label = new JLabel("书名:"+bo.book[index]);
            book_label.setForeground(Color.WHITE);
            book_label.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(book_label);
            updateBox1.add(book_panel);

            updateBox1.add(Box.createVerticalStrut(15)); 

            JPanel author_panel = new JPanel();
            author_panel.setOpaque(false);
            JLabel author_label = new JLabel("作者:"+bo.author[index]);
            author_label.setForeground(Color.WHITE);
            author_label.setFont(new Font("宋体",Font.PLAIN,25));
            author_panel.add(author_label);
            updateBox1.add(author_panel);

            updateBox1.add(Box.createVerticalStrut(15)); 

            JPanel from_panel = new JPanel();
            from_panel.setOpaque(false);
            JLabel from_label = new JLabel("出版社:"+bo.from[index]);
            from_label.setForeground(Color.WHITE);
            from_label.setFont(new Font("宋体",Font.PLAIN,25));
            from_panel.add(from_label);
            updateBox1.add(from_panel);

            updateBox1.add(Box.createVerticalStrut(15)); 

            JPanel exit_panel = new JPanel();
            exit_panel.setOpaque(false);
            JLabel exit_label = new JLabel("是否已借:"+bo.exit[index]);
            exit_label.setForeground(Color.WHITE);
            exit_label.setFont(new Font("宋体",Font.PLAIN,25));
            exit_panel.add(exit_label);
            updateBox1.add(exit_panel);

            updateBox1.add(Box.createVerticalStrut(15)); 

            JPanel name_panel = new JPanel();
            name_panel.setOpaque(false);
            JLabel name_label = new JLabel("借书人:"+bo.name[index]);
            name_label.setForeground(Color.WHITE);
            name_label.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(name_label);
            updateBox1.add(name_panel);

            updateBox1.add(Box.createVerticalStrut(15)); 

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton xiu_btn = new JButton("修改图书信息");
            xiu_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(xiu_btn);
            JButton shan_btn = new JButton("删 除");
            shan_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(shan_btn);
            JButton fan_btn = new JButton("返 回");
            fan_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(fan_btn);
            updateBox1.add(btn_panel);
            updatePane1.add(updateBox1);

            frontLayer.add("updatePane1",updatePane1);
            cardLayout.show(frontLayer,"updatePane1");
            frontLayer.validate();

            fan_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });

            shan_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showDelete();
                }
            });

            xiu_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showXiugai();
                }
            });
    }

    //修改图书信息
    public JPanel xiugaiPane = null;
    public JTextField bookInput1 = null;
    public JTextField authorInput1 = null;
    public JTextField fromInput1 = null;
    public JLabel xiugaiTipsLabel = null;
    public String book_str1;
    public String author_str1;
    public String from_str1;
    public void showXiugai(){
        if(xiugaiPane == null){
            xiugaiPane = new JPanel();
            xiugaiPane.setOpaque(false);

            Box xiugaiBox = Box.createVerticalBox();
            xiugaiBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("修改图书信息");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            xiugaiBox.add(title_panel);

            xiugaiBox.add(Box.createVerticalStrut(30));

            JPanel book_panel = new JPanel();
            book_panel.setOpaque(false);
            JLabel book_label = new JLabel("书名:");
            book_label.setForeground(Color.WHITE);
            book_label.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(book_label);
            bookInput1 = new JTextField(15);
            bookInput1.setFont(new Font("宋体",Font.PLAIN,25));
            bookInput1.setText(bo.book[index]);
            book_panel.add(bookInput1);
            xiugaiBox.add(book_panel);

            xiugaiBox.add(Box.createVerticalStrut(30));
            JPanel author_panel = new JPanel();
            author_panel.setOpaque(false);
            JLabel author_label = new JLabel("作者:");
            author_label.setForeground(Color.WHITE);
            author_label.setFont(new Font("宋体",Font.PLAIN,25));
            author_panel.add(author_label);
            authorInput1 = new JTextField(15);
            authorInput1.setFont(new Font("宋体",Font.PLAIN,25));
            authorInput1.setText(bo.author[index]);
            author_panel.add(authorInput1);
            xiugaiBox.add(author_panel);

            xiugaiBox.add(Box.createVerticalStrut(30));

            JPanel from_panel = new JPanel();
            from_panel.setOpaque(false);
            JLabel from_label = new JLabel("出版社:");
            from_label.setForeground(Color.WHITE);
            from_label.setFont(new Font("宋体",Font.PLAIN,25));
            from_panel.add(from_label);
            fromInput1 = new JTextField(15);
            fromInput1.setFont(new Font("宋体",Font.PLAIN,25));
            fromInput1.setText(bo.from[index]);
            from_panel.add(fromInput1);
            xiugaiBox.add(from_panel);

            xiugaiBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton confirm_btn = new JButton("确认修改");
            confirm_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(confirm_btn);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            xiugaiBox.add(btn_panel);

            xiugaiBox.add(Box.createVerticalStrut(10));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            xiugaiTipsLabel = new JLabel("");
            xiugaiTipsLabel.setForeground(new Color(238,32,32));
            xiugaiTipsLabel.setFont(new Font("宋体",Font.PLAIN,20));
            tips_panel.add(xiugaiTipsLabel);
            xiugaiBox.add(tips_panel);

            xiugaiPane.add(xiugaiBox);

            frontLayer.add("xiugaiPane",xiugaiPane);
            cardLayout.show(frontLayer,"xiugaiPane");
            frontLayer.validate();
            bookInput1.requestFocus();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showUpdate1();
                }
            });

            confirm_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    book_str1 = bookInput1.getText();
                    author_str1 = authorInput1.getText();
                    from_str1 = fromInput1.getText();

                    if("".equals(book_str1)){
                        xiugaiTipsLabel.setText("书名不能为空!");
                        bookInput1.requestFocus();
                    }else if("".equals(author_str1)){
                        xiugaiTipsLabel.setText("作者不能为空!");
                        authorInput1.requestFocus();
                    }else if("".equals(from_str1)){
                        xiugaiTipsLabel.setText("出版社不能为空!");
                        fromInput1.requestFocus();
                    }else{
                        showXiugaiSuccess();
                    }
                }
            });
        }else{
            cardLayout.show(frontLayer,"xiugaiPane");
            bookInput1.setText(bo.book[index]);
            authorInput1.setText(bo.author[index]);
            fromInput1.setText(bo.from[index]);
            xiugaiTipsLabel.setText("");
            bookInput1.requestFocus();
        }
    }

    //修改成功界面
    public JPanel xiuSuccessPane = null;
    public void showXiugaiSuccess(){
        bo.xiugai(book_str1,author_str1,from_str1,index);
        if(xiuSuccessPane == null){
            xiuSuccessPane = new JPanel();
            xiuSuccessPane.setOpaque(false);

            Box xiuSuccessBox = Box.createVerticalBox();
            xiuSuccessBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("修改图书信息");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            xiuSuccessBox.add(title_panel);

            xiuSuccessBox.add(Box.createVerticalStrut(30));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            JLabel tips_label = new JLabel("修改图书信息成功!");
            tips_label.setForeground(Color.WHITE);
            tips_label.setFont(new Font("宋体",Font.PLAIN,25));
            tips_panel.add(tips_label);
            xiuSuccessBox.add(tips_panel);

            xiuSuccessBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            xiuSuccessBox.add(btn_panel);

            xiuSuccessPane.add(xiuSuccessBox);

            frontLayer.add("xiuSuccessPane",xiuSuccessPane);
            cardLayout.show(frontLayer,"xiuSuccessPane");
            frontLayer.validate();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });
        }else{
            cardLayout.show(frontLayer,"xiuSuccessPane");
        }   
    }

    //删除图书界面
    public JPanel deletePane = null;
    public void showDelete(){
            deletePane = new JPanel();
            deletePane.setOpaque(false);

            Box deleteBox = Box.createVerticalBox();
            deleteBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("删除图书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            deleteBox.add(title_panel);

            deleteBox.add(Box.createVerticalStrut(30));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            JLabel tips_label = new JLabel("确认要删除图书《"+bo.book[index]+"》?");
            tips_label.setForeground(Color.WHITE);
            tips_label.setFont(new Font("宋体",Font.PLAIN,25));
            tips_panel.add(tips_label);
            deleteBox.add(tips_panel);

            deleteBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton confirm_btn = new JButton("确认删除");
            confirm_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(confirm_btn);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            deleteBox.add(btn_panel);

            deletePane.add(deleteBox);

            frontLayer.add("deletePane",deletePane);
            cardLayout.show(frontLayer,"deletePane");
            frontLayer.validate();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showUpdate1();
                }
            });

            confirm_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showDeleteSuccess();
                }
            });

    }

    //删除图书成功界面
    public JPanel deleteSuccessPane = null;
    public void showDeleteSuccess(){
        bo.delete(index);
        if(deleteSuccessPane == null){
            deleteSuccessPane = new JPanel();
            deleteSuccessPane.setOpaque(false);

            Box deleteSuccessBox = Box.createVerticalBox();
            deleteSuccessBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("删除图书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            deleteSuccessBox.add(title_panel);

            deleteSuccessBox.add(Box.createVerticalStrut(30));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            JLabel tips_label = new JLabel("删除图书成功!");
            tips_label.setForeground(Color.WHITE);
            tips_label.setFont(new Font("宋体",Font.PLAIN,25));
            tips_panel.add(tips_label);
            deleteSuccessBox.add(tips_panel);

            deleteSuccessBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            deleteSuccessBox.add(btn_panel);

            deleteSuccessPane.add(deleteSuccessBox);

            frontLayer.add("deleteSuccessPane",deleteSuccessPane);
            cardLayout.show(frontLayer,"deleteSuccessPane");
            frontLayer.validate();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });
        }else{
            cardLayout.show(frontLayer,"deleteSuccessPane");
        }   
    }

    //借书
    public JPanel borrowPane = null;
    public JTextField bookInput2 = null;
    public JTextField nameInput2 = null;
    public JLabel borrowTipsLabel = null;
    public String book_str2;
    public String name_str2;
    public int index2;
    public void showBorrow(){
        if( borrowPane == null){
            borrowPane = new JPanel();
            borrowPane.setOpaque(false);

            Box borrowBox = Box.createVerticalBox();
            borrowBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("借书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            borrowBox.add(title_panel);

            borrowBox.add(Box.createVerticalStrut(30));

            JPanel book_panel = new JPanel();
            book_panel.setOpaque(false);
            JLabel book_label = new JLabel("书名:");
            book_label.setForeground(Color.WHITE);
            book_label.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(book_label);
            bookInput2 = new JTextField(15);
            bookInput2.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(bookInput2);
            borrowBox.add(book_panel);

            borrowBox.add(Box.createVerticalStrut(30));

            JPanel name_panel = new JPanel();
            name_panel.setOpaque(false);
            JLabel name_label = new JLabel("借书人:");
            name_label.setForeground(Color.WHITE);
            name_label.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(name_label);
            nameInput2 = new JTextField(15);
            nameInput2.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(nameInput2);
            borrowBox.add(name_panel);

            borrowBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton confirm_btn = new JButton("确 认");
            confirm_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(confirm_btn);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            borrowBox.add(btn_panel);

            borrowBox.add(Box.createVerticalStrut(10));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            borrowTipsLabel = new JLabel("");
            borrowTipsLabel.setForeground(new Color(238,32,32));
            borrowTipsLabel.setFont(new Font("宋体",Font.PLAIN,20));
            tips_panel.add(borrowTipsLabel);
            borrowBox.add(tips_panel);

            borrowPane.add(borrowBox);

            frontLayer.add("borrowPane",borrowPane);
            cardLayout.show(frontLayer,"borrowPane");
            frontLayer.validate();
            bookInput2.requestFocus();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });

            confirm_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    book_str2 = bookInput2.getText();
                    name_str2 = nameInput2.getText();

                    if("".equals(book_str2)){
                        borrowTipsLabel.setText("书名不能为空!");
                        bookInput2.requestFocus();
                    }else if("".equals(name_str2)){
                        borrowTipsLabel.setText("借书人不能为空!");
                        nameInput2.requestFocus();
                    }else{
                        index2 = bo.borrow(book_str2);
                        if(index2==-1){
                            borrowTipsLabel.setText("没有此书!");
                            bookInput2.requestFocus();
                        }else if(index2==-2){
                            borrowTipsLabel.setText("此书已被借出!");
                            bookInput2.requestFocus();
                        }else{
                        showBorrowSuccess();
                        }
                    }
                }
            });
        }else{
            cardLayout.show(frontLayer,"borrowPane");
            bookInput2.setText("");
            nameInput2.setText("");
            borrowTipsLabel.setText("");
            bookInput2.requestFocus();
        }


    }

    //借书成功
    public JPanel jieSuccessPane = null;
    public void showBorrowSuccess(){
        bo.jie(name_str2,index2);
        if(jieSuccessPane == null){
            jieSuccessPane = new JPanel();
            jieSuccessPane.setOpaque(false);

            Box jieSuccessBox = Box.createVerticalBox();
            jieSuccessBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("借书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            jieSuccessBox.add(title_panel);

            jieSuccessBox.add(Box.createVerticalStrut(30));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            JLabel tips_label = new JLabel("借书成功!");
            tips_label.setForeground(Color.WHITE);
            tips_label.setFont(new Font("宋体",Font.PLAIN,25));
            tips_panel.add(tips_label);
            jieSuccessBox.add(tips_panel);

            jieSuccessBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            jieSuccessBox.add(btn_panel);

            jieSuccessPane.add(jieSuccessBox);

            frontLayer.add("jieSuccessPane",jieSuccessPane);
            cardLayout.show(frontLayer,"jieSuccessPane");
            frontLayer.validate();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });
        }else{
            cardLayout.show(frontLayer,"jieSuccessPane");
        }   
    }

    //还书
    public JPanel backPane = null;
    public JTextField bookInput3 = null;
    public JTextField nameInput3 = null;
    public JLabel backTipsLabel = null;
    public String book_str3;
    public String name_str3;
    public int index3;
    public void showBack(){
        if( backPane == null){
            backPane = new JPanel();
            backPane.setOpaque(false);

            Box backBox = Box.createVerticalBox();
            backBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("还书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            backBox.add(title_panel);

            backBox.add(Box.createVerticalStrut(30));

            JPanel book_panel = new JPanel();
            book_panel.setOpaque(false);
            JLabel book_label = new JLabel("书名:");
            book_label.setForeground(Color.WHITE);
            book_label.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(book_label);
            bookInput3 = new JTextField(15);
            bookInput3.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(bookInput3);
            backBox.add(book_panel);

            backBox.add(Box.createVerticalStrut(30));

            JPanel name_panel = new JPanel();
            name_panel.setOpaque(false);
            JLabel name_label = new JLabel("还书人:");
            name_label.setForeground(Color.WHITE);
            name_label.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(name_label);
            nameInput3 = new JTextField(15);
            nameInput3.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(nameInput3);
            backBox.add(name_panel);

            backBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton confirm_btn = new JButton("确 认");
            confirm_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(confirm_btn);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            backBox.add(btn_panel);

            backBox.add(Box.createVerticalStrut(10));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            backTipsLabel = new JLabel("");
            backTipsLabel.setForeground(new Color(238,32,32));
            backTipsLabel.setFont(new Font("宋体",Font.PLAIN,20));
            tips_panel.add(backTipsLabel);
            backBox.add(tips_panel);

            backPane.add(backBox);

            frontLayer.add("backPane",backPane);
            cardLayout.show(frontLayer,"backPane");
            frontLayer.validate();
            bookInput3.requestFocus();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });

            confirm_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    book_str3 = bookInput3.getText();
                    name_str3 = nameInput3.getText();

                    if("".equals(book_str3)){
                        backTipsLabel.setText("书名不能为空!");
                        bookInput3.requestFocus();
                    }else if("".equals(name_str3)){
                        backTipsLabel.setText("还书人不能为空!");
                        nameInput3.requestFocus();
                    }else{
                        index3 = bo.back(book_str3,name_str3);
                        if(index3==-1){
                            backTipsLabel.setText("没有此书!");
                            bookInput3.requestFocus();
                        }else if(index3==-2){
                            backTipsLabel.setText("借书人与还书人不匹配!");
                            nameInput3.requestFocus();
                        }else if(index3 == -3){
                            backTipsLabel.setText("此书没有借出!");
                            bookInput3.requestFocus();
                        }else{
                        showBackSuccess();
                        }
                    }
                }
            });
        }else{
            cardLayout.show(frontLayer,"backPane");
            bookInput3.setText("");
            nameInput3.setText("");
            backTipsLabel.setText("");
            bookInput3.requestFocus();
        }
    }

    //还书成功
    public JPanel backSuccessPane = null;
    public void showBackSuccess(){
        bo.huan(index3);
        if(backSuccessPane == null){
            backSuccessPane = new JPanel();
            backSuccessPane.setOpaque(false);

            Box backSuccessBox = Box.createVerticalBox();
            backSuccessBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("还书");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            backSuccessBox.add(title_panel);

            backSuccessBox.add(Box.createVerticalStrut(30));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            JLabel tips_label = new JLabel("还书成功!");
            tips_label.setForeground(Color.WHITE);
            tips_label.setFont(new Font("宋体",Font.PLAIN,25));
            tips_panel.add(tips_label);
            backSuccessBox.add(tips_panel);

            backSuccessBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            backSuccessBox.add(btn_panel);

            backSuccessPane.add(backSuccessBox);

            frontLayer.add("backSuccessPane",backSuccessPane);
            cardLayout.show(frontLayer,"backSuccessPane");
            frontLayer.validate();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });
        }else{
            cardLayout.show(frontLayer,"backSuccessPane");
        }
    }

    //学员借书情况查询界面
    public JPanel checkPane = null;
    public JTextField nameInput4 = null;
    public JLabel checkTipsLabel =null;
    public String name_str4;
    public String index4;
    public String[] book4 = null;
    public void showCheck(){
        if( checkPane == null){
            checkPane = new JPanel();
            checkPane.setOpaque(false);

            Box checkBox = Box.createVerticalBox();
            checkBox.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("学员借书情况查询");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            checkBox.add(title_panel);

            checkBox.add(Box.createVerticalStrut(30));

            JPanel name_panel = new JPanel();
            name_panel.setOpaque(false);
            JLabel name_label = new JLabel("学员姓名:");
            name_label.setForeground(Color.WHITE);
            name_label.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(name_label);
            nameInput4 = new JTextField(15);
            nameInput4.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(nameInput4);
            checkBox.add(name_panel);

            checkBox.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton confirm_btn = new JButton("确 认");
            confirm_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(confirm_btn);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            checkBox.add(btn_panel);

            checkBox.add(Box.createVerticalStrut(10));

            JPanel tips_panel = new JPanel();
            tips_panel.setOpaque(false);
            checkTipsLabel = new JLabel("");
            checkTipsLabel.setForeground(new Color(238,32,32));
            checkTipsLabel.setFont(new Font("宋体",Font.PLAIN,20));
            tips_panel.add(checkTipsLabel);
            checkBox.add(tips_panel);

            checkPane.add(checkBox);

            frontLayer.add("checkPane",checkPane);
            cardLayout.show(frontLayer,"checkPane");
            frontLayer.validate();
            nameInput4.requestFocus();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showMenu();
                }
            });

            confirm_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    name_str4 = nameInput4.getText();
                    if("".equals(name_str4)){
                        checkTipsLabel.setText("学员姓名不能为空!");
                        nameInput4.requestFocus();
                    }else{
                        index4 = bo.check(name_str4);
                        if("".equals(index4)){
                            checkTipsLabel.setText("此学员没有借书!");
                            nameInput4.requestFocus();
                        }else{
                            showCheck2();
                        //book4 = index4.split(",");
                        }
                    }
                }
            });
        }else{
            cardLayout.show(frontLayer,"checkPane");
            nameInput4.setText("");
            checkTipsLabel.setText("");
            nameInput4.requestFocus();
        }
    }

    //进入学员借书情况查询界面
    public JPanel check2Pane = null;
    public void showCheck2(){
            check2Pane = new JPanel();
            check2Pane.setOpaque(false);

            Box check2Box = Box.createVerticalBox();
            check2Box.add(Box.createVerticalStrut(180));

            JPanel title_panel = new JPanel();
            title_panel.setOpaque(false);
            JLabel title_label = new JLabel("学员借书情况查询");
            title_label.setForeground(Color.WHITE);
            title_label.setFont(new Font("宋体",Font.PLAIN,25));
            title_panel.add(title_label);
            check2Box.add(title_panel);

            check2Box.add(Box.createVerticalStrut(30));

            JPanel name_panel = new JPanel();
            name_panel.setOpaque(false);
            JLabel name_label4 = new JLabel("学员姓名:"+name_str4);
            name_label4.setForeground(Color.WHITE);
            name_label4.setFont(new Font("宋体",Font.PLAIN,25));
            name_panel.add(name_label4);
            check2Box.add(name_panel);

            check2Box.add(Box.createVerticalStrut(15)); 

            JPanel book_panel = new JPanel();
            book_panel.setOpaque(false);
            JLabel book_label4 = new JLabel("已借图书:"+index4);
            book_label4.setForeground(Color.WHITE);
            book_label4.setFont(new Font("宋体",Font.PLAIN,25));
            book_panel.add(book_label4);
            check2Box.add(book_panel);

            check2Box.add(Box.createVerticalStrut(30));

            JPanel btn_panel = new JPanel();
            btn_panel.setOpaque(false);
            JButton return_btn = new JButton("返 回");
            return_btn.setFont(new Font("宋体",Font.PLAIN,15));
            btn_panel.add(return_btn);
            check2Box.add(btn_panel);

            check2Pane.add(check2Box);

            frontLayer.add("check2Pane",check2Pane);
            cardLayout.show(frontLayer,"check2Pane");
            frontLayer.validate();

            return_btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    showCheck();
                }
            });


    }

}

2.系统业务处理文件:LiraryBO.java

import java.io.*;
import java.util.Arrays;

public class LibraryBO{

    public static String[] book = null;
    public static String[] author = null;
    public static String[] from = null;
    public static String[] exit = null;
    public static String[] name = null;
    public static String pass = "admin123";

    //登录功能
    public int login(String password){

            int k = 0;
            if(password.equals(pass)){
                k=-1;
            }else{
                k=0;
            }


        return k;
    }


    //新增图书
    public void add(String nbook,String nauthor,String nfrom){
        read();
        String[] abook=Arrays.copyOf(book,book.length+1);
        abook[book.length]=nbook;
        book = new String[abook.length];
        book = Arrays.copyOf(abook,abook.length);

        String[] aauthor=Arrays.copyOf(author,author.length+1);
        aauthor[author.length]=nauthor;
        author = new String[aauthor.length];
        author = Arrays.copyOf(aauthor,aauthor.length);

        String[] afrom=Arrays.copyOf(from,from.length+1);
        afrom[from.length]=nfrom;
        from = new String[afrom.length];
        from = Arrays.copyOf(afrom,afrom.length);

        String[] aexit=Arrays.copyOf(exit,exit.length+1);
        aexit[exit.length]="否";
        exit = new String[aexit.length];
        exit = Arrays.copyOf(aexit,aexit.length);

        String[] aname=Arrays.copyOf(name,name.length+1);
        aname[name.length]="无";
        name = new String[aname.length];
        name = Arrays.copyOf(aname,aname.length);

        write();
    }

    //图书信息查询.修改、删除
    public int update(String bookName){
        read();
        int index=-1;
        for(int i=0;i<book.length;i++){
            if(bookName.equals(book[i])){
                index=i;
                break;
            }
        }
        return index;
    }

    //修改图书信息
    public void xiugai(String book1,String author1,String from1,int k){
        read();
        book[k]=book1;
        author[k]=author1;
        from[k]=from1;

        write();
    }

    //删除图书信息
    public void delete(int k){
        read();
        String[] book2 = new String[book.length-1];
        for(int i=0;i<book2.length;i++){
            if(k>i){
                book2[i]=book[i];
            }else{
                book2[i]=book[i+1];
            }
        }
        book = new String[book2.length];
        book = Arrays.copyOf(book2,book2.length);

        String[] author2 = new String[author.length-1];
        for(int i=0;i<author2.length;i++){
            if(k>i){
                author2[i]=author[i];
            }else{
                author2[i]=author[i+1];
            }
        }
        author = new String[author2.length];
        author = Arrays.copyOf(author2,author2.length);

        String[] from2 = new String[from.length-1];
        for(int i=0;i<from2.length;i++){
            if(k>i){
                from2[i]=from[i];
            }else{
                from2[i]=from[i+1];
            }
        }
        from = new String[from2.length];
        from = Arrays.copyOf(from2,from2.length);

        String[] exit2 = new String[exit.length-1];
        for(int i=0;i<exit2.length;i++){
            if(k>i){
                exit2[i]=exit[i];
            }else{
                exit2[i]=exit[i+1];
            }
        }
        exit = new String[exit2.length];
        exit = Arrays.copyOf(exit2,exit2.length);

        String[] name2 = new String[name.length-1];
        for(int i=0;i<name2.length;i++){
            if(k>i){
                name2[i]=name[i];
            }else{
                name2[i]=name[i+1];
            }
        }
        name = new String[name2.length];
        name = Arrays.copyOf(name2,name2.length);
        write();

    }   

    //借书
    public int borrow(String book3){
        int k=-1;
        for(int i=0;i<book.length;i++){
            if(book3.equals(book[i])){
                k=i;
                break;
            }
        }
        if(k>-1){
            if("是".equals(exit[k])){
                k=-2;
            }
        }
        return k;

    }

    //借书成功
    public void jie(String name1,int k){
        read();
        name[k]=name1;
        exit[k]="是";

        write();

    }

    //还书
    public int back(String book4,String name4){
        read();
        int k = -1;
        for(int i=0;i<book.length;i++){
            if(book4.equals(book[i])){
                if(exit[i].equals( "否")){
                    k=-3; // 此书没有借出
                }else{
                    if(name4.equals(name[i])){
                        k=i; //还书成功
                        break;
                    }else{
                        k=-2;  //借书人与还书人不一致
                    }
                }
            }
        }
        return k;
    }

    //还书成功
    public void huan(int k){
        read();
        exit[k]="否";
        name[k]="无";
        write();

    }   

    //学员借书情况查询
    public String check(String name5){
        read();
        String k ="";
        int j=0;
        for(int i=0;i<name.length;i++){
            if(name5.equals(name[i])){
                k = k+book[i];
                if(i!=name.length-1){
                    k=k+",";
                }
            }
        }
        return k;
    }


    //读取文件
    public void read(){
        FileReader fr = null;
        BufferedReader br = null;
        try{
            fr = new FileReader("book.txt");
            br = new BufferedReader(fr);

            String line1 = br.readLine();
            book = line1.split(",");

            String line2 = br.readLine();
            author = line2.split(",");

            String line3 = br.readLine();
            from = line3.split(",");

            String line4 = br.readLine();
            exit = line4.split(",");

            String line5 = br.readLine();
            name = line5.split(",");
        }catch(FileNotFoundException e){
            System.out.println("找不到文件!");
        }catch(IOException e){
            System.out.println("IO异常!");
        }finally{
            try{
                if(br!=null){ br.close();}
                if(fr!=null){ fr.close();}
            }catch(IOException e){
                System.out.println("IO异常!");
            }
        }
    }

    //写入
    public void write(){
        FileWriter fw = null;
        BufferedWriter bw = null;
        try{
            fw = new FileWriter("book.txt");
            bw = new BufferedWriter(fw);

            String line1 = "";
            for(int i=0;i<book.length;i++){
                line1 = line1 + book[i];
                if(i!=book.length-1){
                    line1=line1+",";
                }
            }
            bw.write(line1);
            bw.newLine();

            String line2 = "";
            for(int i=0;i<author.length;i++){
                line2= line2+author[i];
                if(i!=author.length-1){
                    line2 = line2+",";
                }
            }
            bw.write(line2);
            bw.newLine();

            String line3 ="";
            for(int i=0;i<from.length;i++){
                line3= line3+from[i];
                if(i!=from.length-1){
                    line3= line3+",";
                }
            }
            bw.write(line3);
            bw.newLine();

            String line4 = "";
            for(int i=0;i<exit.length;i++){
                line4=line4+exit[i];
                if(i!=exit.length-1){
                    line4=line4+",";
                }
            }
            bw.write(line4);
            bw.newLine();

            String line5 = "";
            for(int i=0;i<name.length;i++){
                line5= line5+name[i];
                if(i!=name.length-1){
                    line5=line5+",";
                }
            }
            bw.write(line5);
        }catch(FileNotFoundException e){
            System.out.println("找不到文件!");
        }catch(IOException e){
            System.out.println("IO异常!");
        }finally{
            try{
                if(bw!=null){ bw.close();}
                if(fw!=null){ fw.close();}
            }catch(IOException e){
                System.out.println("IO异常!");
            }
        }
    }

}

 3. 图书存储文件:book.txt
为何家会伤人,白夜行,平凡的世界,1984,小王子
武剑红,未知,路遥,马克.李维,未知
未知,出版社,出版社1,出版社1,出版社2
是,否,否,否,否
小李子,无,无,无,无
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值