练习~图书管理系统

  早期习作~~GUI的练习

  采用卡片式布局,每次访问卡片前都会判断页面是否已经被内存回收。

  一、架构

 

  二、界面

  三、源码

  UI层:

   1 import javax.swing.*;
   2 import java.awt.*;
   3 import java.awt.event.*;
   4 
   5 public class libUI{
   6     //主方法
   7     public static void main(String [] args){
   8         libUI ui = new libUI();
   9         ui.frame();
  10         ui.initBO();
  11         ui.login();
  12     }
  13     
  14     public libBO bo = null;
  15     public void initBO(){
  16         bo = new libBO();
  17     }
  18     
  19     //界面大小
  20     public int w = 820;
  21     public int h = 620;
  22     
  23     public JFrame jf = null;
  24     public JLayeredPane layeredp = null;
  25     public JLayeredPane backlayer = null;
  26     public JPanel picp = null;
  27     public JPanel title = null;
  28     public JLabel subhead = null;
  29     public JPanel frontlayer = null;
  30     public CardLayout cardl = new CardLayout(0, 0);
  31     
  32     //窗口及基本图层
  33     public void frame(){
  34         layeredp = new JLayeredPane();
  35         layeredp.setPreferredSize(new Dimension(w, h));
  36         
  37         //窗口
  38         jf = new JFrame("图书管理系统");
  39         jf.add(layeredp);
  40         jf.setResizable(false);
  41         jf.pack();
  42         jf.setVisible(true);
  43         jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44         
  45         //背景层
  46         backlayer = new JLayeredPane();
  47         backlayer.setSize(w, h);
  48         backlayer.setLocation(0, 0);
  49         //载入图片
  50         picp = new JPanel();
  51         picp.setLayout(cardl);
  52         JLabel bj1 = new JLabel(new ImageIcon("res/1.jpg"));
  53         picp.add("p1", bj1);
  54         JLabel bj2 = new JLabel(new ImageIcon("res/2.jpg"));
  55         picp.add("p2", bj2);
  56         JLabel bj3 = new JLabel(new ImageIcon("res/3.jpg"));
  57         picp.add("p3", bj3);
  58         JLabel bj4 = new JLabel(new ImageIcon("res/4.jpg"));
  59         picp.add("p4", bj4);
  60         picp.setSize(w, h);
  61         picp.setLocation(0, 0);
  62         backlayer.add(picp, new Integer(0));
  63         picp.validate();
  64         //标题
  65         title = new JPanel();
  66         title.setOpaque(false);
  67         Box titlebox = Box.createVerticalBox();
  68         
  69         titlebox.add(Box.createVerticalStrut(80));
  70         
  71         JPanel tittipp = new JPanel();
  72         tittipp.setOpaque(false);
  73         JLabel tittips = new JLabel(new ImageIcon("res/标题-1.png"));
  74         tittipp.add(tittips);
  75         titlebox.add(tittipp);
  76         
  77         JPanel subheadp = new JPanel();
  78         subheadp.setOpaque(false);
  79         subhead = new JLabel();
  80         subhead.setFont(new Font("华文行楷", Font.PLAIN, 30));
  81         subheadp.add(subhead);
  82         titlebox.add(subheadp);
  83         title.add(titlebox);
  84         title.setLocation(0, 0);
  85         title.setSize(w, h);
  86         backlayer.add(title, new Integer(1));
  87         
  88         layeredp.add(backlayer, new Integer(0));
  89         
  90         //前景层
  91         frontlayer = new JPanel();
  92         frontlayer.setLayout(cardl);
  93         frontlayer.setOpaque(false);
  94         frontlayer.setSize(w, h);
  95         frontlayer.setLocation(0, 0);
  96         
  97         layeredp.add(frontlayer, new Integer(1));
  98     }
  99     
 100     //登录层
 101     public JPanel loginp = null;
 102     public JPasswordField logpi = null;
 103     public JLabel logt = null;
 104     public void login(){
 105         if(loginp == null){
 106             //界面
 107             loginp = new JPanel();
 108             loginp.setLayout(null);
 109             loginp.setOpaque(false);
 110             
 111             Box loginbox = Box.createVerticalBox();
 112             loginbox.setLocation(10, 380);
 113             loginbox.setSize(400, 180);
 114             loginp.add(loginbox);
 115             
 116             JPanel denglup = new JPanel();
 117             denglup.setOpaque(false);
 118             JLabel denglu = new JLabel("管理员登陆");
 119             denglu.setForeground(new Color(20, 150, 250));
 120             denglu.setFont(new Font("华文仿宋", Font.BOLD, 25));
 121             denglup.add(denglu);
 122             loginbox.add(denglup);
 123             
 124             JPanel logpp = new JPanel();
 125             logpp.setOpaque(false);
 126             JLabel logpt = new JLabel("登陆密码:");
 127             logpt.setForeground(new Color(20, 150, 250));
 128             logpt.setFont(new Font("华文中宋", Font.PLAIN, 20));
 129             logpi = new JPasswordField(8);
 130             logpi.setForeground(Color.BLUE);
 131             logpi.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 132             logpp.add(logpt);
 133             logpp.add(logpi);
 134             loginbox.add(logpp);
 135             
 136             JPanel logbp =new JPanel();
 137             logbp.setOpaque(false);
 138             JButton logb = new JButton("登   录");
 139             logb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 140             logbp.add(logb);
 141             loginbox.add(logbp);
 142 
 143             JPanel logtp = new JPanel();
 144             logtp.setOpaque(false);
 145             logt = new JLabel(" "); 
 146             logt.setForeground(new Color(238,22,22));
 147             logt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 148             logtp.add(logt);
 149             loginbox.add(logtp);
 150             
 151             //显示
 152             frontlayer.add("login", loginp);
 153             cardl.show(picp, "p1");
 154             cardl.show(frontlayer, "login");
 155             frontlayer.validate();
 156             logpi.requestFocus();
 157             
 158             //监听
 159             logb.addActionListener(new ActionListener(){
 160                 public void actionPerformed(ActionEvent ae){
 161                     char[] passi = logpi.getPassword();
 162                     if(passi.length == 0){
 163                         logt.setText("密码不能为空!");
 164                     }else{
 165                         try {
 166                             int n = bo.dologin(passi);
 167                             if(n == 0){
 168                                 logt.setText("密码错误!");
 169                                 logpi.setText("");
 170                             }else{
 171                                 logt.setText(" ");
 172                                 logpi.setText("");
 173                                 menu();
 174                             }
 175                         } catch (Exception e) {
 176                             logt.setText("出错了!");
 177                         }
 178                     }
 179                 }
 180             });
 181             
 182         }else{
 183             cardl.show(frontlayer, "login");
 184             cardl.show(picp, "p1");
 185             logpi.requestFocus();
 186         }
 187     
 188     }
 189     
 190     //主菜单界面
 191     public JPanel menup = null;
 192     public void menu(){
 193         if(menup == null){
 194             menup = new JPanel();
 195             menup.setOpaque(false);
 196             menup.setLayout(new BorderLayout());
 197             
 198             //左边按钮
 199             Box westbox = Box.createVerticalBox();
 200             menup.add(westbox, BorderLayout.WEST);
 201             
 202             westbox.add(Box.createVerticalStrut(220));
 203             
 204             JButton addb = new JButton("新增图书");
 205             addb.setFont(new Font("华文中宋", Font.PLAIN, 25));
 206             westbox.add(addb);
 207             
 208             westbox.add(Box.createVerticalStrut(80));
 209             
 210             JButton lendb = new JButton("借书");
 211             lendb.setFont(new Font("华文中宋", Font.PLAIN, 25));
 212             westbox.add(lendb);
 213             
 214             westbox.add(Box.createVerticalStrut(80));
 215             
 216             JButton returnb = new JButton("还书");
 217             returnb.setFont(new Font("华文中宋", Font.PLAIN, 25));
 218             westbox.add(returnb);
 219             
 220             //右边按钮
 221             Box eastbox = Box.createVerticalBox();
 222             menup.add(eastbox, BorderLayout.EAST);
 223             
 224             eastbox.add(Box.createVerticalStrut(200));
 225             
 226             JButton bookb = new JButton("<html>图书信息查询<br>【修改/删除】</html>");
 227             bookb.setFont(new Font("华文中宋", Font.PLAIN, 20));
 228             bookb.setAlignmentX(Component.RIGHT_ALIGNMENT);
 229             eastbox.add(bookb);
 230 
 231             eastbox.add(Box.createVerticalStrut(70));
 232             
 233             JButton inquiryb = new JButton("<html>学员借书<br>情况查询</html>");
 234             inquiryb.setFont(new Font("华文中宋", Font.PLAIN, 22));
 235             inquiryb.setAlignmentX(Component.RIGHT_ALIGNMENT);
 236             eastbox.add(inquiryb);
 237             
 238             eastbox.add(Box.createVerticalStrut(70));
 239             
 240             JButton quitb = new JButton("退出");
 241             quitb.setFont(new Font("华文中宋", Font.PLAIN, 25));
 242             quitb.setAlignmentX(Component.RIGHT_ALIGNMENT);
 243             eastbox.add(quitb);
 244             
 245             //显示
 246             frontlayer.add("menu", menup);
 247             cardl.show(picp, "p2");
 248             cardl.show(frontlayer, "menu");
 249             frontlayer.validate();
 250             
 251             //监听
 252             addb.addActionListener(new ActionListener(){
 253                 public void actionPerformed(ActionEvent ae){
 254                     add();
 255                 }
 256             });
 257             
 258             lendb.addActionListener(new ActionListener(){
 259                 public void actionPerformed(ActionEvent ae){
 260                     lend();
 261                 }
 262             });
 263             
 264             returnb.addActionListener(new ActionListener(){
 265                 public void actionPerformed(ActionEvent ae){
 266                     returnbook();
 267                 }
 268             });
 269             
 270             bookb.addActionListener(new ActionListener(){
 271                 public void actionPerformed(ActionEvent ae){
 272                     book();
 273                 }
 274             });
 275             
 276             inquiryb.addActionListener(new ActionListener(){
 277                 public void actionPerformed(ActionEvent ae){
 278                     inquiry();
 279                 }
 280             });
 281             
 282             quitb.addActionListener(new ActionListener(){
 283                 public void actionPerformed(ActionEvent ae){
 284                     quit();
 285                 }
 286             });
 287         }else{
 288             initBO();
 289             cardl.show(picp, "p2");
 290             subhead.setText("");
 291             cardl.show(frontlayer, "menu");
 292         }
 293     }
 294     
 295     //成功提示界面
 296     public JPanel suctipsp = null;
 297     public JLabel suctipsl = null;
 298     public JButton suctipsb = null;
 299     public void suctips(){
 300         if(suctipsp == null){
 301             suctipsp = new JPanel();
 302             suctipsp.setOpaque(false);
 303             Box suctipsbox = Box.createVerticalBox();
 304             suctipsp.add(suctipsbox);
 305             
 306             suctipsbox.add(Box.createVerticalStrut(230));
 307             
 308             JPanel suctipslp = new JPanel();
 309             suctipslp.setOpaque(false);
 310             suctipsl = new JLabel(subhead.getText() + "成功!");
 311             suctipsl.setFont(new Font("华文中宋", Font.PLAIN, 25));
 312             suctipslp.add(suctipsl);
 313             suctipsbox.add(suctipslp);
 314             
 315             suctipsbox.add(Box.createVerticalStrut(30));
 316             
 317             JPanel suctipsbp = new JPanel();
 318             suctipsbp.setOpaque(false);
 319             suctipsb = new JButton("返  回");
 320             suctipsb.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 321             suctipsbp.add(suctipsb);
 322             suctipsbox.add(suctipsbp);
 323             
 324             //显示
 325             frontlayer.add("suctips", suctipsp);
 326             cardl.show(picp, "p4");
 327             cardl.show(frontlayer, "suctips");
 328             frontlayer.validate();
 329             
 330             //监听
 331             suctipsb.addActionListener(new ActionListener(){
 332                 public void actionPerformed(ActionEvent ae){
 333                     menu();
 334                 }
 335             });
 336         }else{
 337             frontlayer.add("suctips", suctipsp);
 338             cardl.show(picp, "p4");
 339             cardl.show(frontlayer, "suctips");
 340             suctipsl.setText(subhead.getText() + "成功!");
 341         }
 342     }
 343     
 344     //新增图书
 345     public JPanel addp = null;
 346     public JTextField addsi = null;
 347     public JTextField addzi = null;
 348     public JTextField addci = null;
 349     public JLabel addt = null;
 350     public void add(){
 351         if(addp == null){
 352             //界面
 353             addp = new JPanel();
 354             addp.setOpaque(false);
 355             Box addbox = Box.createVerticalBox();
 356             addp.add(addbox);
 357             
 358             addbox.add(Box.createVerticalStrut(250));
 359             
 360             JPanel addsp = new JPanel();
 361             addsp.setOpaque(false);
 362             JLabel addst = new JLabel(" 书 名 :");
 363             addst.setFont(new Font("华文中宋", Font.PLAIN, 20));
 364             addsi = new JTextField(8);
 365             addsi.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 366             addsp.add(addst);
 367             addsp.add(addsi);
 368             addbox.add(addsp);
 369             
 370             JPanel addzp = new JPanel();
 371             addzp.setOpaque(false);
 372             JLabel addzt = new JLabel(" 作 者 :");
 373             addzt.setFont(new Font("华文中宋", Font.PLAIN, 20));
 374             addzi = new JTextField(8);
 375             addzi.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 376             addzp.add(addzt);
 377             addzp.add(addzi);
 378             addbox.add(addzp);
 379             
 380             JPanel addcp = new JPanel();
 381             addcp.setOpaque(false);
 382             JLabel addct = new JLabel("出版社:");
 383             addct.setFont(new Font("华文中宋", Font.PLAIN, 20));
 384             addci = new JTextField(8);
 385             addci.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 386             addcp.add(addct);
 387             addcp.add(addci);
 388             addbox.add(addcp);
 389             
 390             addbox.add(Box.createVerticalStrut(30));
 391             
 392             JPanel addbp =new JPanel();
 393             addbp.setOpaque(false);
 394             JButton addqb = new JButton("确  认");
 395             addqb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 396             addbp.add(addqb);
 397             JLabel addbt = new JLabel("    ");
 398             addbt.setFont(new Font("华文中宋", Font.PLAIN, 15));
 399             addbp.add(addbt);
 400             JButton addfb = new JButton("返  回");
 401             addfb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 402             addbp.add(addfb);
 403             addbox.add(addbp);
 404             
 405             addbox.add(Box.createVerticalStrut(20));
 406             
 407             JPanel addtp = new JPanel();
 408             addtp.setOpaque(false);
 409             addt = new JLabel(); 
 410             addt.setForeground(Color.red);
 411             addt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 412             addtp.add(addt);
 413             addbox.add(addtp);
 414             
 415             //显示
 416             frontlayer.add("add", addp);
 417             cardl.show(picp, "p3");
 418             cardl.show(frontlayer, "add");
 419             subhead.setText("新增图书");
 420             
 421             //监听
 422             addqb.addActionListener(new ActionListener(){
 423                 public void actionPerformed(ActionEvent ae){
 424                     if("".equals(addsi.getText())){
 425                         addt.setText("书名不能为空!");
 426                     }else{
 427                         try {
 428                             String s = addsi.getText();
 429                             String z = addzi.getText();
 430                             String c = addci.getText();
 431                             bo.doadd(s, z, c);
 432                             addsuc();
 433                         } catch (Exception e) {
 434                             suctips();
 435                             suctipsl.setText("出  错  了 ~");
 436                         }
 437                     }
 438                 }
 439             });
 440             
 441             addfb.addActionListener(new ActionListener(){
 442                 public void actionPerformed(ActionEvent ae){
 443                     menu();
 444                 }
 445             });
 446         }else{
 447             frontlayer.add("add", addp);
 448             cardl.show(picp, "p3");
 449             cardl.show(frontlayer, "add");
 450             subhead.setText("新增图书");
 451             addt.setText("");
 452             addsi.setText("");
 453             addzi.setText("");
 454             addci.setText("");
 455         }
 456     }
 457     
 458     //增加图书成功
 459     public void addsuc(){
 460         suctips();
 461     }
 462     
 463     //借书
 464     public JPanel lendp = null;
 465     public JTextField lensi = null;
 466     public JTextField lenji = null;
 467     public JLabel lent = null;
 468     public void lend(){
 469         if(lendp == null){
 470             //界面
 471             lendp = new JPanel();
 472             lendp.setOpaque(false);
 473             Box lendbox = Box.createVerticalBox();
 474             lendp.add(lendbox);
 475             
 476             lendbox.add(Box.createVerticalStrut(250));
 477             
 478             JPanel lensp = new JPanel();
 479             lensp.setOpaque(false);
 480             JLabel lenst = new JLabel(" 书 名 :");
 481             lenst.setFont(new Font("华文中宋", Font.PLAIN, 20));
 482             lensi = new JTextField(8);
 483             lensi.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 484             lensp.add(lenst);
 485             lensp.add(lensi);
 486             lendbox.add(lensp);
 487             
 488             lendbox.add(Box.createVerticalStrut(15));
 489             
 490             JPanel lenjp = new JPanel();
 491             lenjp.setOpaque(false);
 492             JLabel lenjt = new JLabel("借书人:");
 493             lenjt.setFont(new Font("华文中宋", Font.PLAIN, 20));
 494             lenji = new JTextField(8);
 495             lenji.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 496             lenjp.add(lenjt);
 497             lenjp.add(lenji);
 498             lendbox.add(lenjp);
 499             
 500             lendbox.add(Box.createVerticalStrut(30));
 501             
 502             JPanel lenbp =new JPanel();
 503             lenbp.setOpaque(false);
 504             JButton lenqb = new JButton("确  认");
 505             lenqb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 506             lenbp.add(lenqb);
 507             JLabel lenbt = new JLabel("    ");
 508             lenbt.setFont(new Font("华文中宋", Font.PLAIN, 15));
 509             lenbp.add(lenbt);
 510             JButton lenfb = new JButton("返  回");
 511             lenfb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 512             lenbp.add(lenfb);
 513             lendbox.add(lenbp);
 514             
 515             lendbox.add(Box.createVerticalStrut(30));
 516             
 517             JPanel lentp = new JPanel();
 518             lentp.setOpaque(false);
 519             lent = new JLabel(); 
 520             lent.setForeground(Color.red);
 521             lent.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 522             lentp.add(lent);
 523             lendbox.add(lentp);
 524             
 525             //显示
 526             frontlayer.add("lend", lendp);
 527             cardl.show(picp, "p3");
 528             cardl.show(frontlayer, "lend");
 529             subhead.setText("借书");
 530             
 531             //监听
 532             lenqb.addActionListener(new ActionListener(){
 533                 public void actionPerformed(ActionEvent ae){
 534                     if("".equals(lensi.getText())){
 535                         lent.setText("书名不能为空!");
 536                     }else if("".equals(lenji.getText())){
 537                         lent.setText("借书人不能为空!");
 538                     }else{
 539                         try {
 540                             String s = lensi.getText();
 541                             String j = lenji.getText();
 542                             int t = bo.dolend(s, j);
 543                             switch(t){
 544                             case 0:
 545                                 lent.setText("该图书不在馆藏范围内!");
 546                                 break;
 547                             case 1:
 548                                 lent.setText("此书已被借出!");
 549                                 break;
 550                             default:
 551                                 lendsuc();
 552                             }
 553                         } catch (Exception e) {
 554                             suctips();
 555                             suctipsl.setText("出  错  了 ~");
 556                         }
 557                     }
 558                 }
 559             });
 560             
 561             lenfb.addActionListener(new ActionListener(){
 562                 public void actionPerformed(ActionEvent ae){
 563                     menu();
 564                 }
 565             });
 566         }else{
 567             frontlayer.add("lend", lendp);
 568             cardl.show(picp, "p3");
 569             cardl.show(frontlayer, "lend");
 570             subhead.setText("借书");
 571             lensi.setText("");
 572             lenji.setText("");
 573             lent.setText("");
 574         }
 575     }
 576     
 577     //借书成功
 578     public void lendsuc(){
 579         suctips();
 580     }
 581     
 582     //还书
 583     public JPanel returnbookp = null;
 584     public JTextField retsi = null;
 585     public JTextField retji = null;
 586     public JLabel rett = null;
 587     public void returnbook(){
 588         if(returnbookp == null){
 589             //界面
 590             returnbookp = new JPanel();
 591             returnbookp.setOpaque(false);
 592             Box returnbookbox = Box.createVerticalBox();
 593             returnbookp.add(returnbookbox);
 594             
 595             returnbookbox.add(Box.createVerticalStrut(250));
 596             
 597             JPanel retsp = new JPanel();
 598             retsp.setOpaque(false);
 599             JLabel retst = new JLabel(" 书 名 :");
 600             retst.setFont(new Font("华文中宋", Font.PLAIN, 20));
 601             retsi = new JTextField(8);
 602             retsi.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 603             retsp.add(retst);
 604             retsp.add(retsi);
 605             returnbookbox.add(retsp);
 606             
 607             returnbookbox.add(Box.createVerticalStrut(15));
 608             
 609             JPanel retjp = new JPanel();
 610             retjp.setOpaque(false);
 611             JLabel retjt = new JLabel("还书人:");
 612             retjt.setFont(new Font("华文中宋", Font.PLAIN, 20));
 613             retji = new JTextField(8);
 614             retji.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 615             retjp.add(retjt);
 616             retjp.add(retji);
 617             returnbookbox.add(retjp);
 618             
 619             returnbookbox.add(Box.createVerticalStrut(30));
 620             
 621             JPanel retbp =new JPanel();
 622             retbp.setOpaque(false);
 623             JButton retqb = new JButton("确  认");
 624             retqb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 625             retbp.add(retqb);
 626             JLabel retbt = new JLabel("    ");
 627             retbt.setFont(new Font("华文中宋", Font.PLAIN, 15));
 628             retbp.add(retbt);
 629             JButton retfb = new JButton("返  回");
 630             retfb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 631             retbp.add(retfb);
 632             returnbookbox.add(retbp);
 633             
 634             returnbookbox.add(Box.createVerticalStrut(30));
 635             
 636             JPanel rettp = new JPanel();
 637             rettp.setOpaque(false);
 638             rett = new JLabel(); 
 639             rett.setForeground(Color.red);
 640             rett.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 641             rettp.add(rett);
 642             returnbookbox.add(rettp);
 643             
 644             //显示
 645             frontlayer.add("returnbook", returnbookp);
 646             cardl.show(picp, "p3");
 647             cardl.show(frontlayer, "returnbook");
 648             subhead.setText("还书");
 649             
 650             //监听
 651             retqb.addActionListener(new ActionListener(){
 652                 public void actionPerformed(ActionEvent ae){
 653                     if("".equals(retsi.getText())){
 654                         rett.setText("书名不能为空!");
 655                     }else if("".equals(retji.getText())){
 656                         rett.setText("还书人不能为空!");
 657                     }else{
 658                         try {
 659                             String s = retsi.getText();
 660                             String h = retji.getText();
 661                             int t = bo.doreturnbook(s, h);
 662                             switch(t){
 663                             case 0:
 664                                 rett.setText("输入有误,未检索到该书!");
 665                                 break;
 666                             case 1:
 667                                 rett.setText("输入有误,此书未被借出!");
 668                                 break;
 669                             case 2:
 670                                 returnbooksuc();
 671                                 break;
 672                             default:
 673                                 rett.setText("借书人与还书人不匹配!");
 674                             }
 675                         } catch (Exception e) {
 676                             suctips();
 677                             suctipsl.setText("出  错  了 ~");
 678                         }
 679                     }
 680                 }
 681             });
 682             
 683             retfb.addActionListener(new ActionListener(){
 684                 public void actionPerformed(ActionEvent ae){
 685                     menu();
 686                 }
 687             });
 688         }else{
 689             frontlayer.add("returnbook", returnbookp);
 690             cardl.show(picp, "p3");
 691             cardl.show(frontlayer, "returnbook");
 692             subhead.setText("还书");
 693             retsi.setText("");
 694             retji.setText("");
 695             rett.setText("");
 696         }
 697     }
 698     
 699     //还书成功
 700     public void returnbooksuc(){
 701         suctips();
 702     }
 703     
 704     //图书信息查询
 705     public JLayeredPane bookpane = null;
 706     public JTextField booki = null;
 707     public JLabel bookt = null;
 708     public void book(){
 709         if(bookpane == null){
 710             //界面
 711             bookpane = new JLayeredPane();
 712             JPanel bookp = new JPanel();
 713             bookp.setOpaque(false);
 714             bookp.setSize(w, h);
 715             bookpane.add(bookp, new Integer(1));
 716             Box bookbox = Box.createVerticalBox();
 717             bookp.add(bookbox);
 718             
 719             bookbox.add(Box.createVerticalStrut(280));
 720             
 721             JPanel booksp = new JPanel();
 722             booksp.setOpaque(false);
 723             JLabel bookst = new JLabel("书名:");
 724             bookst.setFont(new Font("华文中宋", Font.PLAIN, 20));
 725             booki = new JTextField(8);
 726             booki.setFont(new Font("微软雅黑", Font.PLAIN, 20));
 727             booksp.add(bookst);
 728             booksp.add(booki);
 729             bookbox.add(booksp);
 730 
 731             bookbox.add(Box.createVerticalStrut(20));
 732             
 733             JPanel bookbp =new JPanel();
 734             bookbp.setOpaque(false);
 735             JButton bookqb = new JButton("确   认");
 736             bookqb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 737             bookbp.add(bookqb);
 738             JLabel bookbt = new JLabel("    ");
 739             bookbt.setFont(new Font("华文中宋", Font.PLAIN, 15));
 740             bookbp.add(bookbt);
 741             JButton bookfb = new JButton("返   回");
 742             bookfb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 743             bookbp.add(bookfb);
 744             bookbox.add(bookbp);
 745             
 746             bookbox.add(Box.createVerticalStrut(20));
 747             
 748             JPanel booktp = new JPanel();
 749             booktp.setOpaque(false);
 750             bookt = new JLabel(" "); 
 751             bookt.setForeground(Color.red);
 752             bookt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 753             booktp.add(bookt);
 754             bookbox.add(booktp);
 755             
 756             JButton booklb = new JButton("图书浏览");
 757             booklb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 758             booklb.setBounds(580, 540, 100, 30);
 759             booklb.setToolTipText("浏览全部图书信息");
 760             bookpane.add(booklb, new Integer(0));
 761             
 762             //显示
 763             frontlayer.add("book", bookpane);
 764             cardl.show(picp, "p3");
 765             subhead.setText("图书信息查询");
 766             cardl.show(frontlayer, "book");
 767             frontlayer.validate();
 768             booki.requestFocus();
 769             
 770             //监听
 771             bookqb.addActionListener(new ActionListener(){
 772                 public void actionPerformed(ActionEvent ae){
 773                     if("".equals(booki.getText())){
 774                         bookt.setText("书名不能为空!");
 775                     }else{
 776                         try {
 777                             int y = bo.dobook(booki.getText());
 778                             if (y == -1) {
 779                                 bookt.setText("该图书不在馆藏范围内!");
 780                             } else {
 781                                 bookinf();
 782                             }
 783                         } catch (Exception e) {
 784                             suctips();
 785                             suctipsl.setText("出  错  了 ~");
 786                         }
 787                     }
 788                 }
 789             });
 790             
 791             bookfb.addActionListener(new ActionListener(){
 792                 public void actionPerformed(ActionEvent ae){
 793                     menu();
 794                 }
 795             });
 796             
 797             booklb.addActionListener(new ActionListener(){
 798                 public void actionPerformed(ActionEvent ae){
 799                     browse();
 800                 }
 801             });
 802         }else{
 803             initBO();
 804             cardl.show(picp, "p3");
 805             subhead.setText("图书信息查询");
 806             cardl.show(frontlayer, "book");
 807             bookt.setText("");
 808             booki.setText("");
 809             booki.requestFocus();
 810         }
 811     }
 812     
 813     //图书浏览
 814     public JPanel browsep = null;
 815     public JLabel binf = null;
 816     public JLabel brot = null;
 817     public JTextField breym = null;
 818     public void browse(){
 819         if(browsep == null){
 820             //界面
 821             browsep = new JPanel();
 822             browsep.setOpaque(false);
 823             Box browsebox = Box.createVerticalBox();
 824             browsep.add(browsebox);
 825             
 826             browsebox.add(Box.createVerticalStrut(160));
 827             
 828             JPanel brobbp =new JPanel();
 829             brobbp.setOpaque(false);
 830             JButton broback = new JButton("返回");
 831             broback.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 832             brobbp.add(broback);
 833             JLabel brobbt = new JLabel("                                                              ");
 834             brobbt.setFont(new Font("华文中宋", Font.PLAIN, 15));
 835             brobbp.add(brobbt);
 836             browsebox.add(brobbp);
 837             
 838             browsebox.add(Box.createVerticalStrut(10));
 839             
 840             JPanel binfp = new JPanel();
 841             binfp.setOpaque(false);
 842             binf = new JLabel();
 843             binf.setFont(new Font("华文中宋", Font.PLAIN, 20));
 844             binfp.add(binf);
 845             browsebox.add(binfp);
 846             
 847             browsebox.add(Box.createVerticalStrut(10));
 848             
 849             JPanel brobp =new JPanel();
 850             brobp.setOpaque(false);
 851             JButton brolast = new JButton("上一本");
 852             brolast.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 853             brobp.add(brolast);
 854             JLabel brobt = new JLabel("    ");
 855             brobt.setFont(new Font("华文中宋", Font.PLAIN, 15));
 856             brobp.add(brobt);
 857             JButton bronext = new JButton("下一本");
 858             bronext.setFont(new Font("微软雅黑", Font.PLAIN, 15));
 859             brobp.add(bronext);
 860             browsebox.add(brobp);
 861             
 862             browsebox.add(Box.createVerticalStrut(10));
 863             
 864             JPanel brotp = new JPanel();
 865             brotp.setOpaque(false);
 866             JLabel brot1 = new JLabel("第");
 867             brot1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 868             breym = new JTextField(2);
 869             breym.setToolTipText("你可以改变此数值,再点击 上一本/下一本 实现跳转");
 870             breym.setText("1");
 871             breym.setFont(new Font("微软雅黑", Font.PLAIN, 16));
 872             JLabel brot2 = new JLabel("本 / ");
 873             brot2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 874             brot = new JLabel();
 875             brot.setFont(new Font("微软雅黑", Font.PLAIN, 18));
 876             brotp.add(brot1);
 877             brotp.add(breym);
 878             brotp.add(brot2);
 879             brotp.add(brot);
 880             browsebox.add(brotp);
 881             
 882             //显示
 883             try {
 884                 bo.liulan();
 885                 brot.setText("共 " + bo.rlength() + " 本");
 886                 binf.setText("<html>"
 887                         +"书  名  : "+bo.dobookinf(1)+"<br>"
 888                         +"<br>"
 889                         +"作  者  : "+bo.dobookinf(2)+"<br>"
 890                         +"<br>"
 891                         +"出 版 社:"+bo.dobookinf(3)+"<br>"
 892                         +"<br>"
 893                         +"是否已借:"+bo.dobookinf(4)+"<br>"
 894                         +"<br>"
 895                         +"借 书 人:"+bo.dobookinf(5)
 896                         +"</html>");
 897             } catch (Exception e) {
 898                 suctips();
 899                 suctipsl.setText("出  错  了 ~");
 900             }
 901             frontlayer.add("browse", browsep);
 902             cardl.show(frontlayer, "browse");
 903             frontlayer.validate();
 904             
 905             //监听
 906             broback.addActionListener(new ActionListener(){
 907                 public void actionPerformed(ActionEvent ae){
 908                     book();
 909                 }
 910             });
 911             
 912             brolast.addActionListener(new ActionListener(){
 913                 public void actionPerformed(ActionEvent ae){
 914                     int ym = bo.last(Integer.valueOf(breym.getText()));
 915                     try {
 916                         if (ym == 0){
 917                             brot.setForeground(Color.red);
 918                         }else{
 919                             breym.setText(ym + "");
 920                             brot.setForeground(Color.DARK_GRAY);
 921                             binf.setText("<html>" + "书  名  : " + bo.dobookinf(1)
 922                                     + "<br>" + "<br>" + "作  者  : "
 923                                     + bo.dobookinf(2) + "<br>" + "<br>"
 924                                     + "出 版 社:" + bo.dobookinf(3) + "<br>"
 925                                     + "<br>" + "是否已借:" + bo.dobookinf(4)
 926                                     + "<br>" + "<br>" + "借 书 人:"
 927                                     + bo.dobookinf(5) + "</html>");
 928                         }
 929                     } catch (Exception e) {
 930                         suctips();
 931                         suctipsl.setText("出  错  了 ~");
 932                     }
 933                 }
 934             });
 935             
 936             bronext.addActionListener(new ActionListener(){
 937                 public void actionPerformed(ActionEvent ae){
 938                     int ym = bo.next(Integer.valueOf(breym.getText()));
 939                     try {
 940                         if (ym == 0){
 941                             brot.setForeground(Color.red);
 942                         }else{
 943                             breym.setText(ym + "");
 944                             brot.setForeground(Color.DARK_GRAY);
 945                             binf.setText("<html>" + "书  名  : " + bo.dobookinf(1)
 946                                     + "<br>" + "<br>" + "作  者  : "
 947                                     + bo.dobookinf(2) + "<br>" + "<br>"
 948                                     + "出 版 社:" + bo.dobookinf(3) + "<br>"
 949                                     + "<br>" + "是否已借:" + bo.dobookinf(4)
 950                                     + "<br>" + "<br>" + "借 书 人:"
 951                                     + bo.dobookinf(5) + "</html>");
 952                         }
 953                     } catch (Exception e) {
 954                         suctips();
 955                         suctipsl.setText("出  错  了 ~");
 956                     }
 957                 }
 958             });
 959         }else{
 960             brot.setForeground(Color.DARK_GRAY);
 961             cardl.show(frontlayer, "browse");
 962             try {
 963                 bo.liulan();
 964                 breym.setText("1");
 965                 brot.setText("共 " + bo.rlength() + " 本");
 966                 binf.setText("<html>"
 967                         +"书  名  : "+bo.dobookinf(1)+"<br>"
 968                         +"<br>"
 969                         +"作  者  : "+bo.dobookinf(2)+"<br>"
 970                         +"<br>"
 971                         +"出 版 社:"+bo.dobookinf(3)+"<br>"
 972                         +"<br>"
 973                         +"是否已借:"+bo.dobookinf(4)+"<br>"
 974                         +"<br>"
 975                         +"借 书 人:"+bo.dobookinf(5)
 976                         +"</html>");
 977             } catch (Exception e) {
 978                 suctips();
 979                 suctipsl.setText("出  错  了 ~");
 980             }
 981         }
 982     }
 983     
 984     //图书信息显示
 985     public JPanel bookinfp = null;
 986     public JLabel inf = null;
 987     public void bookinf(){
 988         if(bookinfp == null){
 989             //界面
 990             bookinfp = new JPanel();
 991             bookinfp.setOpaque(false);
 992             Box bookinfbox = Box.createVerticalBox();
 993             bookinfp.add(bookinfbox);
 994             
 995             bookinfbox.add(Box.createVerticalStrut(220));
 996             
 997             JPanel infp = new JPanel();
 998             infp.setOpaque(false);
 999             inf = new JLabel();
1000             inf.setHorizontalAlignment(SwingConstants.CENTER);
1001             inf.setFont(new Font("华文中宋", Font.PLAIN, 20));
1002             infp.add(inf);
1003             bookinfbox.add(infp);
1004             
1005             bookinfbox.add(Box.createVerticalStrut(20));
1006             
1007             JPanel infbp = new JPanel();
1008             JButton reviseb = new JButton("修改图书信息");
1009             reviseb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1010             infbp.add(reviseb);
1011             JButton delb = new JButton("删除");
1012             delb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1013             infbp.add(delb);
1014             JButton backb = new JButton("返回");
1015             backb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1016             infbp.add(backb);
1017             bookinfbox.add(infbp);
1018             
1019             //显示
1020             try {
1021                 inf.setText("<html>"
1022                         +"书  名  : "+bo.dobookinf(1)+"<br>"
1023                         +"<br>"
1024                         +"作  者  : "+bo.dobookinf(2)+"<br>"
1025                         +"<br>"
1026                         +"出 版 社:"+bo.dobookinf(3)+"<br>"
1027                         +"<br>"
1028                         +"是否已借:"+bo.dobookinf(4)+"<br>"
1029                         +"<br>"
1030                         +"借 书 人:"+bo.dobookinf(5)
1031                         +"</html>");
1032             } catch (Exception e) {
1033                 suctips();
1034                 suctipsl.setText("出  错  了 ~");
1035             }
1036             frontlayer.add("bookinf", bookinfp);
1037             cardl.show(frontlayer, "bookinf");
1038             frontlayer.validate();
1039             
1040             //监听
1041             delb.addActionListener(new ActionListener(){
1042                 public void actionPerformed(ActionEvent ae){
1043                     try {
1044                         int t = bo.doifdel();
1045                         if(t == 1){
1046                             suctips();
1047                             suctipsl.setText("图书《" + bo.dobookinf(1) + "》已被借出,无法删除!");
1048                         }else{
1049                             delete();
1050                         }
1051                     } catch (Exception e) {
1052                         suctips();
1053                         suctipsl.setText("出  错  了 ~");
1054                     }
1055                 }
1056             });
1057             
1058             reviseb.addActionListener(new ActionListener(){
1059                 public void actionPerformed(ActionEvent ae){
1060                     revise();
1061                     revsi.setText(bo.dobookinf(1));
1062                     revzi.setText(bo.dobookinf(2));
1063                     revci.setText(bo.dobookinf(3));
1064                 }
1065             });
1066             
1067             backb.addActionListener(new ActionListener(){
1068                 public void actionPerformed(ActionEvent ae){
1069                     book();
1070                 }
1071             });
1072         }else{
1073             cardl.show(frontlayer, "bookinf");
1074             try {
1075                 inf.setText("<html>"
1076                         +"书  名  : "+bo.dobookinf(1)+"<br>"
1077                         +"<br>"
1078                         +"作  者  : "+bo.dobookinf(2)+"<br>"
1079                         +"<br>"
1080                         +"出 版 社:"+bo.dobookinf(3)+"<br>"
1081                         +"<br>"
1082                         +"是否已借:"+bo.dobookinf(4)+"<br>"
1083                         +"<br>"
1084                         +"借 书 人:"+bo.dobookinf(5)
1085                         +"</html>");
1086             } catch (Exception e) {
1087                 suctips();
1088                 suctipsl.setText("出  错  了 ~");
1089             }
1090         }
1091     }
1092     
1093     //修改图书信息
1094     public JPanel revisep = null;
1095     public JTextField revsi = null;
1096     public JTextField revzi = null;
1097     public JTextField revci = null;
1098     public JLabel revt = null;
1099     public void revise(){
1100         if(revisep == null){
1101             //界面
1102             revisep = new JPanel();
1103             revisep.setOpaque(false);
1104             Box revisebox = Box.createVerticalBox();
1105             revisep.add(revisebox);
1106             
1107             revisebox.add(Box.createVerticalStrut(250));
1108             
1109             JPanel revsp = new JPanel();
1110             revsp.setOpaque(false);
1111             JLabel revst = new JLabel(" 书 名 :");
1112             revst.setFont(new Font("华文中宋", Font.PLAIN, 20));
1113             revsi = new JTextField(8);
1114             revsi.setFont(new Font("微软雅黑", Font.PLAIN, 18));
1115             revsp.add(revst);
1116             revsp.add(revsi);
1117             revisebox.add(revsp);
1118             
1119             JPanel revzp = new JPanel();
1120             revzp.setOpaque(false);
1121             JLabel revzt = new JLabel(" 作 者 :");
1122             revzt.setFont(new Font("华文中宋", Font.PLAIN, 20));
1123             revzi = new JTextField(8);
1124             revzi.setFont(new Font("微软雅黑", Font.PLAIN, 18));
1125             revzp.add(revzt);
1126             revzp.add(revzi);
1127             revisebox.add(revzp);
1128             
1129             JPanel revcp = new JPanel();
1130             revcp.setOpaque(false);
1131             JLabel revct = new JLabel("出版社:");
1132             revct.setFont(new Font("华文中宋", Font.PLAIN, 20));
1133             revci = new JTextField(8);
1134             revci.setFont(new Font("微软雅黑", Font.PLAIN, 18));
1135             revcp.add(revct);
1136             revcp.add(revci);
1137             revisebox.add(revcp);
1138             
1139             revisebox.add(Box.createVerticalStrut(30));
1140             
1141             JPanel revbp =new JPanel();
1142             revbp.setOpaque(false);
1143             JButton revqb = new JButton("确认修改");
1144             revqb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1145             revbp.add(revqb);
1146             JLabel revbt = new JLabel("    ");
1147             revbt.setFont(new Font("华文中宋", Font.PLAIN, 15));
1148             revbp.add(revbt);
1149             JButton revfb = new JButton("返  回");
1150             revfb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1151             revbp.add(revfb);
1152             revisebox.add(revbp);
1153             
1154             revisebox.add(Box.createVerticalStrut(30));
1155             
1156             JPanel revtp = new JPanel();
1157             revtp.setOpaque(false);
1158             revt = new JLabel(); 
1159             revt.setForeground(Color.red);
1160             revt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
1161             revtp.add(revt);
1162             revisebox.add(revtp);
1163             
1164             //显示
1165             frontlayer.add("revise", revisep);
1166             cardl.show(frontlayer, "revise");
1167             subhead.setText("修改图书信息");
1168             
1169             //监听
1170             revqb.addActionListener(new ActionListener(){
1171                 public void actionPerformed(ActionEvent ae){
1172                     if("".equals(revsi.getText())){
1173                         revt.setText("书名不能为空!");
1174                     }else{
1175                         try {
1176                             String s = revsi.getText();
1177                             String z = revzi.getText();
1178                             String c = revci.getText();
1179                             bo.dorevise(s, z, c);
1180                             revisesuc();
1181                         } catch (Exception e) {
1182                             suctips();
1183                             suctipsl.setText("出  错  了 ~");
1184                         }
1185                     }
1186                 }
1187             });
1188             
1189             revfb.addActionListener(new ActionListener(){
1190                 public void actionPerformed(ActionEvent ae){
1191                     bookinf();
1192                 }
1193             });
1194         }else{
1195             frontlayer.add("revise", revisep);
1196             cardl.show(frontlayer, "revise");
1197             subhead.setText("修改图书信息");
1198             revt.setText("");
1199         }
1200     }
1201     
1202     //修改成功
1203     public void revisesuc(){
1204         suctips();
1205     }
1206     
1207     //删除图书
1208     public JPanel deletep = null;
1209     public JLabel delt = null;
1210     public void delete(){
1211         if(deletep == null){
1212             deletep = new JPanel();
1213             deletep.setOpaque(false);
1214             Box deletebox = Box.createVerticalBox();
1215             deletep.add(deletebox);
1216             
1217             deletebox.add(Box.createVerticalStrut(240));
1218             
1219             JPanel deltp = new JPanel();
1220             deltp.setOpaque(false);
1221             delt = new JLabel("确定要删除图书《" + bo.dobookinf(1) + "》?");
1222             delt.setFont(new Font("微软雅黑", Font.PLAIN, 25));
1223             deltp.add(delt);
1224             deletebox.add(deltp);
1225             
1226             deletebox.add(Box.createVerticalStrut(30));
1227             
1228             JPanel delbp =new JPanel();
1229             delbp.setOpaque(false);
1230             JButton delqb = new JButton("确认删除");
1231             delqb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1232             delbp.add(delqb);
1233             JLabel delbt = new JLabel("    ");
1234             delbt.setFont(new Font("华文中宋", Font.PLAIN, 15));
1235             delbp.add(delbt);
1236             JButton delfb = new JButton("返  回");
1237             delfb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1238             delbp.add(delfb);
1239             deletebox.add(delbp);
1240             
1241             //显示
1242             frontlayer.add("delete", deletep);
1243             cardl.show(frontlayer, "delete");
1244             cardl.show(picp, "p4");
1245             subhead.setText("删除图书");
1246             
1247             //监听
1248             delqb.addActionListener(new ActionListener(){
1249                 public void actionPerformed(ActionEvent ae){
1250                     try {
1251                         bo.dodelete();
1252                     } catch (Exception e) {
1253                         suctips();
1254                         suctipsl.setText("出  错  了 ~");
1255                     }
1256                     deletesuc();
1257                 }
1258             });
1259             
1260             delfb.addActionListener(new ActionListener(){
1261                 public void actionPerformed(ActionEvent ae){
1262                     cardl.show(picp, "p3");
1263                     bookinf();
1264                 }
1265             });
1266         }else{
1267             frontlayer.add("delete", deletep);
1268             cardl.show(frontlayer, "delete");
1269             cardl.show(picp, "p4");
1270             subhead.setText("删除图书");
1271             delt.setText("确定要删除图书《" + bo.dobookinf(1) + "》?");
1272         }
1273     }
1274     
1275     //删除图书成功
1276     public void deletesuc(){
1277         suctips();
1278     }
1279     
1280     //学员借书情况查询
1281     public JPanel inquiryp = null;
1282     public JTextField inquiryi = null;
1283     public JLabel inquiryt = null;
1284     public void inquiry(){
1285         if(inquiryp == null){
1286             //界面
1287             inquiryp = new JPanel();
1288             inquiryp.setOpaque(false);
1289             Box inquirybox = Box.createVerticalBox();
1290             inquiryp.add(inquirybox);
1291             
1292             inquirybox.add(Box.createVerticalStrut(280));
1293             
1294             JPanel inquirysp = new JPanel();
1295             inquirysp.setOpaque(false);
1296             JLabel inquiryst = new JLabel("学员信息:");
1297             inquiryst.setFont(new Font("华文中宋", Font.PLAIN, 20));
1298             inquiryi = new JTextField(8);
1299             inquiryi.setFont(new Font("微软雅黑", Font.PLAIN, 20));
1300             inquirysp.add(inquiryst);
1301             inquirysp.add(inquiryi);
1302             inquirybox.add(inquirysp);
1303 
1304             inquirybox.add(Box.createVerticalStrut(20));
1305             
1306             JPanel inquirybp =new JPanel();
1307             inquirybp.setOpaque(false);
1308             JButton inquiryqb = new JButton("确  认");
1309             inquiryqb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1310             inquirybp.add(inquiryqb);
1311             JLabel inquirybt = new JLabel("    ");
1312             inquirybt.setFont(new Font("华文中宋", Font.PLAIN, 15));
1313             inquirybp.add(inquirybt);
1314             JButton inquiryfb = new JButton("返  回");
1315             inquiryfb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1316             inquirybp.add(inquiryfb);
1317             inquirybox.add(inquirybp);
1318             
1319             inquirybox.add(Box.createVerticalStrut(20));
1320             
1321             JPanel inquirytp = new JPanel();
1322             inquirytp.setOpaque(false);
1323             inquiryt = new JLabel(); 
1324             inquiryt.setForeground(Color.red);
1325             inquiryt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
1326             inquirytp.add(inquiryt);
1327             inquirybox.add(inquirytp);
1328             
1329             //显示
1330             frontlayer.add("inquiry", inquiryp);
1331             cardl.show(picp, "p3");
1332             subhead.setText("学员借书情况查询");
1333             cardl.show(frontlayer, "inquiry");
1334             frontlayer.validate();
1335             inquiryi.requestFocus();
1336             
1337             //监听
1338             inquiryqb.addActionListener(new ActionListener(){
1339                 public void actionPerformed(ActionEvent ae){
1340                     if("".equals(inquiryi.getText())){
1341                         inquiryt.setText("学员姓名不能为空!");
1342                         inquiryi.requestFocus();
1343                     }else{
1344                         inquiryinf();
1345                     }
1346                 }
1347             });
1348             
1349             inquiryfb.addActionListener(new ActionListener(){
1350                 public void actionPerformed(ActionEvent ae){
1351                     menu();
1352                 }
1353             });
1354             
1355         }else{
1356             initBO();
1357             cardl.show(picp, "p3");
1358             subhead.setText("学员借书情况查询");
1359             cardl.show(frontlayer, "inquiry");
1360             inquiryt.setText("");
1361             inquiryi.setText("");
1362             inquiryi.requestFocus();
1363         }
1364     }
1365     
1366     //学员借书信息
1367     public JPanel peopleinfp = null;
1368     public JLabel pinf = null;
1369     public void inquiryinf(){
1370         if(peopleinfp == null){
1371             //界面
1372             peopleinfp = new JPanel();
1373             peopleinfp.setOpaque(false);
1374             Box peopleinfbox = Box.createVerticalBox();
1375             peopleinfp.add(peopleinfbox);
1376             
1377             peopleinfbox.add(Box.createVerticalStrut(250));
1378             
1379             JPanel infp = new JPanel();
1380             infp.setOpaque(false);
1381             pinf = new JLabel();
1382             pinf.setFont(new Font("华文中宋", Font.PLAIN, 22));
1383             infp.add(pinf);
1384             peopleinfbox.add(infp);
1385             
1386             peopleinfbox.add(Box.createVerticalStrut(20));
1387             
1388             JPanel pinfbp = new JPanel();
1389             pinfbp.setOpaque(false);
1390             JButton pbackb = new JButton("返回");
1391             pbackb.setFont(new Font("微软雅黑", Font.PLAIN, 15));
1392             pinfbp.add(pbackb);
1393             peopleinfbox.add(pinfbp);
1394             
1395             //显示
1396             frontlayer.add("peopleinf", peopleinfp);
1397             cardl.show(picp, "p4");
1398             cardl.show(frontlayer, "peopleinf");
1399             frontlayer.validate();
1400             try {
1401                 pinf.setText("<html>"
1402                         +"学员姓名: "+inquiryi.getText()+"<br>"
1403                         +"<br>"
1404                         +"已借图书: "+bo.doinquiry(inquiryi.getText())+"<br>"
1405                         +"</html>");
1406             } catch (Exception e) {
1407                 suctips();
1408                 suctipsl.setText("出  错  了 ~");
1409             }
1410             
1411             //监听
1412             pbackb.addActionListener(new ActionListener(){
1413                 public void actionPerformed(ActionEvent ae){
1414                     inquiry();
1415                 }
1416             });
1417             
1418         }else{
1419             cardl.show(frontlayer, "peopleinf");
1420             cardl.show(picp, "p4");
1421             try {
1422                 pinf.setText("<html>"
1423                         +"学员姓名: "+inquiryi.getText()+"<br>"
1424                         +"<br>"
1425                         +"已借图书: "+bo.doinquiry(inquiryi.getText())+"<br>"
1426                         +"</html>");
1427             } catch (Exception e) {
1428                 suctips();
1429                 suctipsl.setText("出  错  了 ~");
1430             }
1431         }
1432     }
1433     
1434     
1435     //退出
1436     public void quit(){
1437         login();
1438     }
1439     
1440 }

  业务层

  1 public class libBO{
  2     
  3     public libData da = new libData();
  4     public int n = -1;
  5     
  6     //登录
  7     public int dologin(char[] p) throws Exception{
  8         String str = String.valueOf(p);
  9         if(str.equals(da.readpassword())){
 10             return 1;
 11         }else{
 12             return 0;
 13         }
 14     }
 15     
 16     //增加图书
 17     public void doadd(String s, String z, String c){
 18         da.read();
 19         
 20         int t = da.length() + 1;
 21         //书名
 22         String[] l1 = new String[t];
 23         for( int i = 0; i < l1.length - 1; i++){
 24             l1[i] = da.shuming()[i];
 25         }
 26         l1[l1.length - 1] = s;
 27         da.shumingrewrite(l1);
 28         //作者
 29         String[] l2 = new String[t];
 30         for( int i = 0; i < l2.length - 1; i++){
 31             l2[i] = da.zuozhe()[i];
 32         }
 33         if("".equals(z)){
 34             l2[l2.length - 1] = "不详";
 35         }else{
 36             l2[l2.length - 1] = z;
 37         }
 38         da.zuozherewrite(l2);
 39         //出版社
 40         String[] l3 = new String[t];
 41         for( int i = 0; i < l3.length - 1; i++){
 42             l3[i] = da.chubanshe()[i];
 43         }
 44         if("".equals(c)){
 45             l3[l3.length - 1] = "不详";
 46         }else{
 47             l3[l3.length - 1] = c;
 48         }
 49         da.chubansherewrite(l3);
 50         //是否已借
 51         String[] l4 = new String[t];
 52         for( int i = 0; i < l4.length - 1; i++){
 53             l4[i] = da.yijie()[i];
 54         }
 55         l4[l4.length - 1] = "否";
 56         da.yijierewrite(l4);
 57         //借书人
 58         String[] l5 = new String[t];
 59         for( int i = 0; i < l5.length - 1; i++){
 60             l5[i] = da.jieshuren()[i];
 61         }
 62         l5[l5.length - 1] = "无";
 63         da.jieshurenrewrite(l5);
 64         
 65         da.write();
 66     }
 67     
 68     //借书
 69     public int dolend(String s, String j){
 70         dobook(s);
 71         if(n == -1){
 72             return 0;
 73         }else if("是".equals(da.yijie()[n])){
 74             return 1;
 75         }else{
 76             da.jieshurenrevise(j, n);
 77             da.yijierevise("是", n);
 78             da.write();
 79             return 2;
 80         }
 81     }
 82     
 83     //还书
 84     public int doreturnbook(String s, String h){
 85         dobook(s);
 86         if(n == -1){
 87             return 0;
 88         }else if("否".equals(da.yijie()[n])){
 89             return 1;
 90         }else if(h.equals(da.jieshuren()[n])){
 91             da.jieshurenrevise("无", n);
 92             da.yijierevise("否", n);
 93             da.write();
 94             return 2;
 95         }else{
 96             return 3;
 97         }
 98     }
 99     
100     //图书查找
101     public int dobook(String r){
102         da.read();
103         String[] s = da.shuming();
104         for(int i = 0; i < s.length; i++){
105             if(r.equals(s[i])){
106                 n = i;
107             }
108         }
109         return n;
110     }
111     
112     //返回数组长度
113     public int rlength(){
114         da.read();
115         return da.length();
116     }
117     
118     //图书浏览:从第一本开始浏览
119     public void liulan(){
120         n = 0;
121     }
122     
123     //图书浏览:上一本
124     public int last(int b){
125         da.read();
126         if(b < 1 || b > da.length()){
127             return 0;
128         }
129         n = b - 1;
130         if(n == 0){
131             n = da.length() - 1;
132         }else{
133             n = n - 1;
134         }
135         return n+1;
136     }
137     
138     //图书浏览:下一本
139     public int next(int b){
140         da.read();
141         if(b < 1 || b > da.length()){
142             return 0;
143         }
144         n = b - 1;
145         if(n == (da.length() - 1)){
146             n = 0;
147         }else{
148             n = n + 1;
149         }
150         return n+1;
151     }
152     
153     //图书信息显示
154     public String dobookinf(int i){
155         da.read();
156         switch (i)
157         {
158             case 1 : return da.shuming()[n];
159             case 2 : return da.zuozhe()[n];
160             case 3 : return da.chubanshe()[n];
161             case 4 : return da.yijie()[n];
162             default : return da.jieshuren()[n];
163         }
164     }
165     
166     //图书信息修改
167     public void dorevise(String s, String z, String c){
168         da.read();
169         da.shumingrevise(s, n);
170         if("".equals(z)){
171             da.zuozherevise("不详", n);
172         }else{
173             da.zuozherevise(z, n);
174         }
175         if("".equals(c)){
176             da.chubansherevise("不详", n);
177         }else{
178             da.chubansherevise(c, n);
179         }
180         da.write();
181     }
182     
183     //删除图书前判断是否已借
184     public int doifdel(){
185         da.read();
186         if("是".equals(da.yijie()[n])){
187             return 1;
188         }
189         return 0;
190     }
191     
192     //删除图书
193     public void dodelete(){
194         da.read();
195         int t = da.length() - 1;
196         String[] l1 = new String[t];
197         String[] l2 = new String[t];
198         String[] l3 = new String[t];
199         String[] l4 = new String[t];
200         String[] l5 = new String[t];
201         for(int i = 0; i < da.length(); i++){
202             if(da.shuming()[i].equals(da.shuming()[n])){
203                 for(int x = i + 1; x < da.length(); x++) {
204                     l1[x-1] = da.shuming()[x];
205                     l2[x-1] = da.zuozhe()[x];
206                     l3[x-1] = da.chubanshe()[x];
207                     l4[x-1] = da.yijie()[x];
208                     l5[x-1] = da.jieshuren()[x];
209                 }
210                 break;
211             }else{
212                 l1[i] = da.shuming()[i];
213                 l2[i] = da.zuozhe()[i];
214                 l3[i] = da.chubanshe()[i];
215                 l4[i] = da.yijie()[i];
216                 l5[i] = da.jieshuren()[i];
217             }
218         }
219         da.shumingrewrite(l1);
220         da.zuozherewrite(l2);
221         da.chubansherewrite(l3);
222         da.yijierewrite(l4);
223         da.jieshurenrewrite(l5);
224         da.write();
225     }
226     
227     //学员借书情况
228     public String doinquiry(String p){
229         da.read();
230         String[] j = da.jieshuren();
231         String s = "";
232         for(int i = 0; i < j.length; i++){
233             if(p.equals(j[i])){
234                 s = s + da.shuming()[i] + "、";
235             }
236         }
237         if("".equals(s)){
238             return "无";
239         }else{
240             s = s.substring(0,s.length()-1);
241             return s;
242         }
243     }
244     
245 }
View Code

  数据层

  1 import java.io.*;
  2 
  3 public class libData{
  4 
  5     public static String[] shuming= null;
  6     public static String[] zuozhe= null;
  7     public static String[] chubanshe= null;
  8     public static String[] yijie= null;
  9     public static String[] jieshuren= null;
 10     
 11     //返回数组
 12     public String[] shuming(){
 13         return shuming;
 14     }
 15     
 16     public String[] zuozhe(){
 17         return zuozhe;
 18     }
 19     
 20     public String[] chubanshe(){
 21         return chubanshe;
 22     }
 23     
 24     public String[] yijie(){
 25         return yijie;
 26     }
 27     
 28     public String[] jieshuren(){
 29         return jieshuren;
 30     }
 31     
 32     //返回数组长度
 33     public int length(){
 34         return shuming.length;
 35     }
 36     
 37     //重写数组
 38     public void shumingrewrite(String[] s){
 39         shuming = s;
 40     }
 41     
 42     public void zuozherewrite(String[] z){
 43         zuozhe = z;
 44     }
 45     
 46     public void chubansherewrite(String[] c){
 47         chubanshe = c;
 48     }
 49     
 50     public void yijierewrite(String[] y){
 51         yijie = y;
 52     }
 53     
 54     public void jieshurenrewrite(String[] j){
 55         jieshuren = j;
 56     }
 57     
 58     //更改数组元素
 59     public void shumingrevise(String s, int n){
 60         shuming[n] = s;
 61     }
 62     
 63     public void zuozherevise(String z, int n){
 64         zuozhe[n] = z;
 65     }
 66     
 67     public void chubansherevise(String c, int n){
 68         chubanshe[n] = c;
 69     }
 70     
 71     public void yijierevise(String y, int n){
 72         yijie[n] = y;
 73     }
 74     
 75     public void jieshurenrevise(String j, int n){
 76         jieshuren[n] = j;
 77     }
 78     
 79     //读取密码
 80     public String readpassword() {
 81         FileReader fr = null;
 82         BufferedReader br = null ;
 83         try {
 84             fr = new FileReader("admin.txt");
 85             br = new BufferedReader(fr) ;
 86 
 87             return br.readLine();
 88         }catch(FileNotFoundException e){
 89             throw new RuntimeException();
 90         }catch(IOException e){
 91             throw new RuntimeException();
 92         }finally{
 93             try{
 94                 if(br != null){ br.close(); }
 95                 if(fr != null){ fr.close(); }
 96             }catch(IOException e){
 97                 throw new RuntimeException();
 98             }
 99         }
100     }
101     
102     //读取
103     public void read(){
104         FileReader fr = null;
105         BufferedReader br = null;
106         try {
107             fr = new FileReader("book.txt");
108             br = new BufferedReader(fr) ;
109             
110             String line1r = br.readLine();
111             String[] line1 = line1r.split(":");
112             String shumingr = line1[1];
113             shuming = shumingr.split(",");
114             
115             String line2r = br.readLine();
116             String[] line2 = line2r.split(":");
117             String zuozher = line2[1];
118             zuozhe = zuozher.split(",");
119             
120             String line3r = br.readLine();
121             String[] line3 = line3r.split(":");
122             String chubansher = line3[1];
123             chubanshe = chubansher.split(",");
124             
125             String line4r = br.readLine();
126             String[] line4 = line4r.split(":");
127             String yijier = line4[1];
128             yijie = yijier.split(",");
129             
130             String line5r = br.readLine();
131             String[] line5 = line5r.split(":");
132             String jieshurenr = line5[1];
133             jieshuren = jieshurenr.split(",");
134             /*
135             for(int t = 0; t < shuming.length; t++){
136                 System.out.print(shuming[t]);
137                 System.out.print(",");
138             }
139             System.out.println("");
140             System.out.println(shuming.length);
141             */
142         } catch (FileNotFoundException e) {
143             throw new RuntimeException();
144         } catch (IOException e) {
145             throw new RuntimeException();
146         }finally{
147             try {
148                 if(br != null){
149                     br.close();
150                 }
151                 if(fr != null){
152                     fr.close();
153                 }
154             }catch (IOException e) {
155                 throw new RuntimeException();
156             } 
157         }
158     }
159     
160     //写入
161     public void write(){
162         FileWriter fw = null;
163         BufferedWriter bw = null;
164         try{
165             fw = new FileWriter("book.txt");
166             bw = new BufferedWriter(fw);
167             
168             String line1 = "      书         名     :";
169             for(int i = 0; i < shuming.length; i++){
170                 line1 = line1 + shuming[i] + ",";
171             }
172             line1 = line1.substring(0,line1.length()-1);
173             bw.write(line1);
174             bw.newLine();
175             
176             String line2 = "      作         者     :";
177             for(int i = 0; i < zuozhe.length; i++){
178                 line2 = line2 + zuozhe[i] + ",";
179             }
180             line2 = line2.substring(0,line2.length()-1);
181             bw.write(line2);
182             bw.newLine();    
183             
184             String line3 = "    出     版     社   :";
185             for(int i = 0; i < chubanshe.length; i++){
186                 line3 = line3 + chubanshe[i] + ",";
187             }
188             line3 = line3.substring(0,line3.length()-1);
189             bw.write(line3);
190             bw.newLine();
191             
192             String line4 = "是否已借(是/否):";
193             for(int i = 0; i < yijie.length; i++){
194                 line4 = line4 + yijie[i] + ",";
195             }
196             line4 = line4.substring(0,line4.length()-1);
197             bw.write(line4);
198             bw.newLine();
199             
200             String line5 = "借书人(###/无):";
201             for(int i = 0; i < jieshuren.length; i++){
202                 line5 = line5 + jieshuren[i] + ",";
203             }
204             line5 = line5.substring(0,line5.length()-1);
205             bw.write(line5);
206         }catch(FileNotFoundException e){
207             throw new RuntimeException();
208         }catch(IOException e){
209             throw new RuntimeException();
210         }finally{
211             try{
212                 if(bw != null){ bw.close(); }
213                 if(fw != null){ fw.close(); }
214             }catch(IOException e){
215                 throw new RuntimeException();
216             }
217         }
218     }
219 }
View Code

 

posted @ 2017-04-26 11:04  枫林晚月  阅读(792)  评论(1编辑  收藏  举报