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

📄 filesystem.java

📁 以文件形式来存储数据的学生管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {
               JOptionPane.showMessageDialog(null,"请点击删除按钮!");
               return;
            }
            else
            {
            	zhong.removeAllElements();
            	try{
            	   BufferedReader fin = new BufferedReader(new FileReader(MyFile1));
            	   while((s = fin.readLine())!= null)
            		  zhong.addElement(s);
                   fin.close();
                   i=0;
                   if((i=zhong.indexOf(idT.getText(),i))!=-1){
                      j=i+5;
                      for(t=i;t<=j;t++)
                      	 zhong.removeElement(zhong.get(i));
                      try{           	
                          i=0;
                       	  j=zhong.size();
                       	  zf="";
                       	  while(i<j){     //把变量的内容连接成字符串
                       		  zf=zf + (String)zhong.get(i)+'\r';
                       	      i++;
                       	      }
                          BufferedReader in2 = new BufferedReader(new StringReader(zf));//把字符串添加到文本文件
                          PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(MyFile1)));
                          while((s = in2.readLine()) != null ){
                              out1.println(s);
                             
                              }
                          out1.close();
                      } 
                      catch(EOFException d) {
                          JOptionPane.showMessageDialog(null,"出错了");
                          return;
                      }
                   }
                } catch (IOException g) {
            				// TODO Auto-generated catch block
                     	JOptionPane.showMessageDialog(null,"出错了");
                     	return;
            	}
                     JOptionPane.showMessageDialog(null,"删除成功!");
                     idT.setText("");
                     nameT.setText("");
                     sexT.setText("");
                     ageT.setText("");
                     coleageT.setText("");
                     departmentT.setText("");                
 
            }
  }

}
class btnOk3_actionAdapter implements java.awt.event.ActionListener{ 
deleInfo adaptee; 
btnOk3_actionAdapter(deleInfo adaptee){ 
this.adaptee=adaptee; 
} 
public void actionPerformed(ActionEvent e){ 
adaptee.btnOk3_actionPerformed(e); 
} 
} 
///////////////////////////////////////////////
////////////////////////////////////////////////
class JFinfo extends JFrame{
    String id = new String();
    String name = new String();
    String sex = new String();
    String age = new String();
    String coleage = new String();
    String department = new String();
    String zf = new String();
    char ch;
    int chi,j=0,i,t;
    String s, s2 = new String();
   JFinfo(){}
}
/////////////////////////////////////////
////////////////////////////////////////
class meframe extends JFinfo implements ActionListener,ItemListener{
JLabel ta;
JMenuBar mb;
JMenu sys,add,modify,dele,about; 
JMenuItem f1,f2;
JMenuItem e1,e2,e3;
JMenuItem h3;
JToolBar jtb;
FileDialog fd,fs; 
PrinterJob prtMe = PrinterJob.getPrinterJob(); 
JFileChooser fc = new JFileChooser(); 
Clipboard clipbd=getToolkit().getSystemClipboard();
JScrollPane jsp;
JScrollBar jsb;
int newflag=1;
String stitle;
meframe()
{
Container c=getContentPane(); 
c.setLayout(new BorderLayout());
Icon normalIcon=new ImageIcon("load_pic2.gif");
ta=new JLabel(normalIcon);
jsp=new JScrollPane(ta);
jsp.setPreferredSize(new Dimension(30, 50)); 
jsb=new JScrollBar(); 
jtb=new JToolBar();
mb=new JMenuBar();
sys=new JMenu("查询");
add=new JMenu("添加");
modify=new JMenu("修改");
dele=new JMenu("删除"); 
about=new JMenu("关于");

mb.add(sys);
mb.add(add);
mb.add(modify);
mb.add(dele);
mb.add(about);
c.add("North",mb);
jtb.setFloatable(true);

c.add(jsp, BorderLayout.CENTER); 
f1=new JMenuItem("查询学生信息");
sys.add(f1);
f1.addActionListener(this);
add.addSeparator();
e1=new JMenuItem("添加学生信息");
add.add(e1);
e1.addActionListener(this);
e2=new JMenuItem("修改学生信息");
modify.add(e2);
//modify.addSeparator();
e2.addActionListener(this);
e3=new JMenuItem("删除学生信息");
//dele.addSeparator();
dele.add(e3);
e3.addActionListener(this);
h3=new JMenuItem("关于");
//about.addSeparator();
about.add(h3);
h3.addActionListener(this);
f2=new JMenuItem("退出");
about.add(f2);
f2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==f1)//查询
{
    Vector zhong=new Vector(60,6);
    Vector zg=new Vector(6,6);
     File MyPath=new File("\\File");
    if(!MyPath.exists())
        MyPath.mkdir();
    File MyFile1=new File("DataFile.txt");   

     String idid = JOptionPane.showInputDialog("请输入要查询的学生学号");
     if(idid.trim()!=""){
              	
            	zhong.removeAllElements();
                	try{
                	    BufferedReader fin = new BufferedReader(new FileReader(MyFile1));
                	    while((s = fin.readLine())!= null)
                		    zhong.addElement(s);
                       fin.close();
                       i=0;
                       if((i=zhong.indexOf(idid,i))!=-1){
                          j=i+5;
                          for(t=i;t<=j;t++)
                      	    zg.addElement(zhong.get(t));
 searchInfo loin=new searchInfo();
               loin.setTitle("查询学生信息"); 
               loin.show();   
loin.idT.setText((String)zg.get(0));
                   loin.nameT.setText((String)zg.get(1));
                    loin.sexT.setText((String)zg.get(2));
                    loin.ageT.setText((String)zg.get(3));
                    loin.coleageT.setText((String)zg.get(4));
                    loin.departmentT.setText((String)zg.get(5));
                    
                      }



                      else
                          JOptionPane.showMessageDialog(null,"对不起,没有您要查询的学生信息!");
                        
                    }
                    catch(Exception ex)
                    {
                         JOptionPane.showMessageDialog(null,ex+"抱歉,程序出现异常!");
                    }
                
    
             }  
}
if(e.getSource()==f2)//退出
{
System.exit(0);
}


if(e.getSource()==e1)//添加学生信息
{
addInfo addin=new addInfo();
  addin.setTitle("添加学生信息"); 
  addin.show();
}

if(e.getSource()==e2)//修改学生信息
{
    Vector zhong=new Vector(60,6);
    Vector zg=new Vector(6,6);
     File MyPath=new File("\\File");
    if(!MyPath.exists())
        MyPath.mkdir();
    File MyFile1=new File("DataFile.txt");   

     String idid = JOptionPane.showInputDialog("请输入要修改的学生学号");
     
     if(idid.trim()!=""){
              	
            	zhong.removeAllElements();
                	try{
                	    BufferedReader fin = new BufferedReader(new FileReader(MyFile1));
                	    while((s = fin.readLine())!= null)
                		    zhong.addElement(s);
                       fin.close();
                       i=0;
                       if((i=zhong.indexOf(idid,i))!=-1){
                          j=i+5;
                          for(t=i;t<=j;t++)
                      	    zg.addElement(zhong.get(t));
alterInfo altin=new alterInfo();
               altin.setTitle("修改学生信息"); 
               altin.show();   
altin.idT.setText((String)zg.get(0));
                   altin.nameT.setText((String)zg.get(1));
                    altin.sexT.setText((String)zg.get(2));
                    altin.ageT.setText((String)zg.get(3));
                    altin.coleageT.setText((String)zg.get(4));
                    altin.departmentT.setText((String)zg.get(5));
                      }
                      else
                          JOptionPane.showMessageDialog(null,"对不起,没有您要修改的学生信息!");
                        
                    }
                    catch(Exception ex)
                    {
                         JOptionPane.showMessageDialog(null,ex+"抱歉,程序出现异常!");
                    }
                
     
                    
             }  

}
if(e.getSource()==e3)//删除学生信息
{ 
     Vector zhong=new Vector(60,6);
    Vector zg=new Vector(6,6);
      File MyPath=new File("\\File");
    if(!MyPath.exists())
        MyPath.mkdir();
    File MyFile1=new File("DataFile.txt");   
String idDel = JOptionPane.showInputDialog("请输入要删除的员工工号");
        if(idDel.trim()!="")
       {
            	zhong.removeAllElements();
            	try{
            	    BufferedReader fin = new BufferedReader(new FileReader(MyFile1));
            	    while((s = fin.readLine())!= null)
            		    zhong.addElement(s);
                   fin.close();
                   i=0;
                   if((i=zhong.indexOf(idDel,i))!=-1){
                      j=i+5;
                      for(t=i;t<=j;t++)
                  	    zg.addElement(zhong.get(t));
 deleInfo delin=new deleInfo();
               delin.setTitle("删除学生信息"); 
               delin.show();   
delin.idT.setText((String)zg.get(0));
                   delin.nameT.setText((String)zg.get(1));
                    delin.sexT.setText((String)zg.get(2));
                    delin.ageT.setText((String)zg.get(3));
                    delin.coleageT.setText((String)zg.get(4));
                    delin.departmentT.setText((String)zg.get(5));
                  }
                  else
                      JOptionPane.showMessageDialog(null,"对不起,没有您要删除的员工信息!");
                    
                }
                catch(Exception ex)
                {
                     JOptionPane.showMessageDialog(null,ex+"抱歉,程序出现异常!");
                }
              
                    
             }  
         }

if(e.getSource()==h3)//关于
{
JOptionPane.showMessageDialog(null, "该JAVA系统由数信院信息02班 庞添尹制作"); 
}
}
public void itemStateChanged(ItemEvent e){}
}

⌨️ 快捷键说明

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