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

📄 mainjframe.java

📁 图书管系统 通讯录系统 java实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                JOptionPane.showMessageDialog(null, "对不起,输入框不能为空,请重新输入!!", "Tips", JOptionPane.INFORMATION_MESSAGE);            }                        else{                //判断该通讯录是否存在                if(file6.exists() ){                    try{                        ObjectInputStream input = new ObjectInputStream( new FileInputStream( file6 ));                        data = ( Object[][] )input.readObject();                        jTable.setModel(new DefaultTableModel(data, columnNames));                        input.close();                    }                    catch(Exception ex){}                    fixDemo.dispose();                }                               //不存在的话,提示错误                  else{                    JOptionPane.showMessageDialog(null, "对不起,该通讯录不存在!请重新输入!", "Tips", JOptionPane.INFORMATION_MESSAGE);                               }            }        }                //fixDemo的取消按钮处理器        if(e.getSource() == jbtCancelXG) {fixDemo.dispose();}                           //保存按钮处理器        if(e.getSource() == jbtBC) {            Object[][] datas = new Object[60][9];            Object[][] temp = new Object[1][1], newdatas = new Object[1][1];            int flag = -1;            DefaultTableModel model = (DefaultTableModel)jTable.getModel();            for( int i=0, n=model.getRowCount(); i<n; i++ ){                for( int j=0; j<9; j++ )                    datas[i][j] = model.getValueAt(i, j);            }            try{                ObjectOutputStream output = new ObjectOutputStream( new FileOutputStream( file6 ));                output.writeObject( datas );                output.close();            }catch(Exception ex){ }            if(totalFile.exists()){                try{                       ObjectInputStream input = new ObjectInputStream( new FileInputStream( totalFile ));                                     temp = (Object[][])input.readObject();                    input.close();                }catch(Exception ex){ }                                //设置标志位flag,用与判别是保存新建的通讯录,还是修改的通讯录                for(int i=0;  i<60 && flag ==-1;  i++){                    for(int j=i; j<temp.length; j+=60){                        if( datas[i][0] != null  &&  datas[i][0].equals(temp[j][0]) ) {                            flag = j;                            break;                        }                    }                                  }                //根据flag做不同的处理:                if( flag != -1 ) { //保存修改的通讯录                    newdatas = temp;                    int location = ( flag / 60 ) * 60;                    for( int i=location; i<location+60; i++) {                        for( int j=0; j<9; j++ )                            newdatas[i][j] = datas[i-location][j];                    }                }                else{ //保存新建的通讯录                    newdatas = new Object[temp.length + 60][9];                    for( int i =0; i<temp.length; i++ ){                        for( int j=0; j<9; j++ )                            newdatas[i][j] = temp[i][j];                    }                    for( int i= temp.length;  i<newdatas.length; i++ ){                        for( int j=0; j<9; j++ )                            newdatas[i][j] = datas[i-temp.length][j];                    }                }                                if( newdatas != null){                    try{                        ObjectOutputStream outputTotalfile = new ObjectOutputStream( new FileOutputStream( totalFile ));                        outputTotalfile.writeObject( newdatas );                        outputTotalfile.close();                    }catch( Exception ex ){}                }                else{                    JOptionPane.showMessageDialog(null, "ERROR!没有进行新建或修改通讯录不能保存。", "Tips", JOptionPane.INFORMATION_MESSAGE);                }            }            else{                newdatas = new Object[60][9];                for(int i=0; i<60; i++){                    for(int j=0; j<9; j++){                             newdatas[i][j] = datas[i][j];                        }                }                if(!newdatas[0][0].equals("")){                    try{                        ObjectOutputStream outputTotalfile = new ObjectOutputStream( new FileOutputStream( totalFile ));                        outputTotalfile.writeObject( newdatas );                        outputTotalfile.close();                    }catch(Exception ex){}                }                else{                    JOptionPane.showMessageDialog(null, "ERROR!没有进行新建或修改通讯录不能保存。", "Tips", JOptionPane.INFORMATION_MESSAGE);                }                          }            jTable.setModel( new DefaultTableModel(0,0) );        }                //删除按钮的处理器        if(e.getSource() == jbtSC) {                   //再打开删除按钮后置输入框的内容为空                jtfSchool.setText("");                jtfXueYuan.setText("");                jtfZhuanYe.setText("");                jtfGrade.setText("");                jtfClass.setText("");                                    jbtOKSC = new JButton("确定");            jbtCancelSC = new JButton("取消");                                    deleteDemo = new JFrame();            deleteDemo.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);            deleteDemo.setTitle("DeleteDemo");            deleteDemo.setSize(200, 230);                        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();            int x = (screenSize.width-deleteDemo.getWidth())/2;            int y = (screenSize.height-deleteDemo.getHeight())/2;                        deleteDemo.setLocation(x, y);            deleteDemo.setVisible(true);            deleteDemo.setResizable(false);                        Container container = deleteDemo.getContentPane();            container.setLayout(new GridLayout(6,2,10,10));                                  container.add(jlbSchool);            container.add(jtfSchool);            container.add(jlbXueYuan);            container.add(jtfXueYuan);            container.add(jlbZhuanYe);            container.add(jtfZhuanYe);            container.add(jlbGrade);            container.add(jtfGrade);            container.add(jlbClass);            container.add(jtfClass);            container.add(jbtOKSC);            container.add(jbtCancelSC);                        jbtOKSC.addActionListener(this);            jbtCancelSC.addActionListener(this);                        //为了美观需要,把jtable置为空的            jTable.setModel( new DefaultTableModel(0,0) );                                }                //删除框的确定按钮的处理器        if(e.getSource() == jbtOKSC) {                        Object[][] datas = new Object[60][9];             Object[][] temp = new Object[60][9];            Object[][] newdatas = new Object[60][9];            int flag = -1;                        file1 = new File("." , jtfSchool.getText());            file2 = new File(file1.getAbsoluteFile()+"//"+ jtfXueYuan.getText() );            file3 = new File(file2.getAbsoluteFile()+"//"+ jtfZhuanYe.getText() );            file4 = new File(file3.getAbsoluteFile()+"//"+ jtfGrade.getText() );            file5 = new File(file4.getAbsoluteFile()+"//"+ jtfClass.getText() );            file6 = new File(file5.getAbsoluteFile()+"//"+ "adressbook.txt" );                        //读入要删除的班别的通讯录            try{                ObjectInputStream input = new ObjectInputStream( new FileInputStream( file6 ));                datas = (Object[][])input.readObject();                input.close();            }catch(Exception ex){ }            //读入总通讯录以更新            try{                   ObjectInputStream input = new ObjectInputStream( new FileInputStream( totalFile ));                                 temp = (Object[][])input.readObject();                input.close();                }catch(Exception ex){ }            //找到要删除的班别在总通讯录的位置            for(int i=0;  i<60 && flag==-1;  i++){                 for(int j=i; j<temp.length; j+=60){                     if( datas[i][0] != null  &&  datas[i][0].equals(temp[j][0]) ) {                          flag = j;                          break;                        }                    }                                  }             int location = ( flag / 60 ) * 60;            //用newdatas来储存新的总通讯录            for(int i=0; i<location; i++){                for(int j=0; j<9; j++){                    newdatas[i][j] = temp[i][j];                }            }            for(int i=location+60; i<temp.length; i++){                for(int j=0; j<9; j++){                    newdatas[i-60][j] = temp[i][j];                }            }           //把newdatas写入总通讯录             try{                 ObjectOutputStream outputTotalfile = new ObjectOutputStream( new FileOutputStream( totalFile ));                 outputTotalfile.writeObject( newdatas );                 outputTotalfile.close();                }catch(Exception ex){}                          file6.delete();            if(file6.exists()){                JOptionPane.showMessageDialog(null, "删除操作不成功!", "Tips", JOptionPane.INFORMATION_MESSAGE);            }            else{                JOptionPane.showMessageDialog(null, "该通讯录不存在或已被成功删除!", "Tips", JOptionPane.INFORMATION_MESSAGE);            }            deleteDemo.dispose();                    }                //删除框的取消按钮的处理器        if(e.getSource() == jbtCancelSC) {deleteDemo.dispose();}                //查询按钮的处理器        if(e.getSource() == jbtCX) {           jTable.setModel( new DefaultTableModel(0,0) );            new SearchFrame();           }           //统计按钮的处理器        if(e.getSource() == jbtTJ) {           jTable.setModel( new DefaultTableModel(0,0) );            new StatisticFrame();        }                //文件按钮的处理器        if(e.getSource() == jcbWJ) {            String stringChoose = jcbWJ.getSelectedItem().toString();            if(stringChoose.equals("导入Excel")){                            }                        if(stringChoose.equals("导出Excel")){                jbtOKOE = new JButton("确定");                jbtCancelOE = new JButton("取消");                                        //再打开编辑按钮后置输入框的内容为空                    jtfSchool.setText("");                    jtfXueYuan.setText("");                    jtfZhuanYe.setText("");                    jtfGrade.setText("");                    jtfClass.setText("");                       outDemo = new JFrame();                    outDemo.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);                    outDemo.setTitle("导出Excel");                    outDemo.setSize(200, 230);                                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();                    int x = (screenSize.width-outDemo.getWidth())/2;                    int y = (screenSize.height-outDemo.getHeight())/2;                                outDemo.setLocation(x, y);                    outDemo.setVisible(true);                    outDemo.setResizable(false);                                Container container = outDemo.getContentPane();                    container.setLayout(new GridLayout(6,2,10,10));                                          container.add(jlbSchool);                    container.add(jtfSchool);                    container.add(jlbXueYuan);                    container.add(jtfXueYuan);                    container.add(jlbZhuanYe);                    container.add(jtfZhuanYe);                    container.add(jlbGrade);                    container.add(jtfGrade);                    container.add(jlbClass);                    container.add(jtfClass);                    container.add(jbtOKOE);                    container.add(jbtCancelOE);                                jbtOKOE.addActionListener(this);                    jbtCancelOE.addActionListener(this);                                }        }        if(e.getSource()==jbtOKOE){            file1 = new File("." , jtfSchool.getText());            file2 = new File(file1.getAbsoluteFile()+"//"+ jtfXueYuan.getText() );            file3 = new File(file2.getAbsoluteFile()+"//"+ jtfZhuanYe.getText() );            file4 = new File(file3.getAbsoluteFile()+"//"+ jtfGrade.getText() );            file5 = new File(file4.getAbsoluteFile()+"//"+ jtfClass.getText() );            file6 = new File(file5.getAbsoluteFile()+"//"+ "adressbook.txt" );                        if(file6.exists()){                                                        }            else{                JOptionPane.showMessageDialog(null,"要导出班的通讯录不存在!", "Tips",JOptionPane.INFORMATION_MESSAGE);            }        }        if(e.getSource()==jbtCancelOE){            outDemo.dispose();        }        //退出按钮处理器        if(e.getSource() == jbtTC) {System.exit(0);}         }}

⌨️ 快捷键说明

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