English Sentence Loading...
英语句子加载中...

Java信息注册模板源码

import java.util.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
class 信息 extends Panel
{
String 邮箱,姓名,职称,单位地址,联系电话,编号,类型,邮编;
信息(String 编号,String 姓名,String 类型,String 单位地址,String 职称,String 联系电话,String 邮编,String 邮箱)
{
   this.编号=编号;
   this.姓名=姓名;
   this.类型=类型;
   this.单位地址=单位地址;
   this.职称=职称;
   this.联系电话=联系电话;
   this.邮编=邮编;
   this.邮箱=邮箱;
}
}

class ShowWin extends JFrame implements ActionListener
{  
LinkedList Xx_list=null;
JTextField 编号文本框=new JTextField(),
姓名文本框=new JTextField(),
类型文本框=new JTextField(),
单位地址文本框=new JTextField(),
职称文本框=new JTextField(),
联系电话文本框=new JTextField(),
邮编文本框=new JTextField(),
邮箱文本框=new JTextField();
JButton b_add=new JButton("add"),
b_save=new JButton("save"),
b_update=new JButton("update"),
b_del=new JButton("delete"),
b_exit=new JButton("exit");
JTextArea 显示区=new JTextArea();

ShowWin()
{
Xx_list=new LinkedList();
Container con=getContentPane();
JScrollPane pane=new JScrollPane(显示区);
显示区.setEditable(false);
JPanel xinxi=new JPanel();xinxi.setLayout(new GridLayout(4,4));
xinxi.add(new Label("编号:"));xinxi.add(编号文本框);
xinxi.add(new Label("姓名:"));xinxi.add(姓名文本框);
xinxi.add(new Label("类型:"));xinxi.add(类型文本框);
xinxi.add(new Label("单位地址:"));xinxi.add(单位地址文本框);
xinxi.add(new Label("职称:"));xinxi.add(职称文本框);
xinxi.add(new Label("联系电话:"));xinxi.add(联系电话文本框);
xinxi.add(new Label("邮编:"));xinxi.add(邮编文本框);
xinxi.add(new Label("邮箱:"));xinxi.add(邮箱文本框);


JPanel edit=new JPanel();
edit.setLayout(new GridLayout(1,5));
edit.add(b_add);
edit.add(b_save);
edit.add(b_update);
edit.add(b_del);
edit.add(b_exit);

JPanel show=new JPanel();
show.setLayout(new BorderLayout());
show.add(pane,BorderLayout.CENTER);
JSplitPane split_one,split_two;
split_one=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,xinxi,edit);
split_two=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,split_one,show);
con.add(split_two,BorderLayout.CENTER);
b_add.addActionListener(this);
b_save.addActionListener(this);
b_update.addActionListener(this);
b_del.addActionListener(this);
b_exit.addActionListener(this);
   }
public void actionPerformed(ActionEvent e)
{
   if(e.getSource()==b_add)
   {
     String xingming=null,zhicheng=null,danweidizhi=null,youxiang=null,lianxidianhua=null,bianhao=null,leixing=null,youbian=null;
     xingming=姓名文本框.getText();zhicheng=职称文本框.getText();
     leixing=类型文本框.getText();youbian=邮编文本框.getText();
     danweidizhi=单位地址文本框.getText();youxiang=邮箱文本框.getText();
     lianxidianhua=联系电话文本框.getText();bianhao=编号文本框.getText();
     信息 xx=new 信息(bianhao,xingming,leixing,danweidizhi,zhicheng,lianxidianhua,youxiang,youbian);
     Xx_list.add(xx);
     try {FileOutputStream file=new FileOutputStream("xx.txt");
          ObjectOutputStream out=new   ObjectOutputStream(file);
          out.writeObject(Xx_list);
          out.close();
         }
     catch(IOException event){}
    }
    else if(e.getSource()==b_del)
    {
   String bianhao=编号文本框.getText();
      try {FileInputStream come_in=new FileInputStream("xx.txt");
          ObjectInputStream in=new   ObjectInputStream(come_in);
          Xx_list=(LinkedList)in.readObject();in.close();
         }
      catch(ClassNotFoundException event){}
      catch(IOException event){}
      for(int i=0;i<Xx_list.size();i++)
      {
       信息 temp=(信息)Xx_list.get(i);
         if(temp.编号.equals(bianhao))
         {
          Xx_list.remove(i);
         }
         try   {
          FileOutputStream file=new FileOutputStream("xx.txt");
              ObjectOutputStream out=new   ObjectOutputStream(file);
              out.writeObject(Xx_list);
              out.close();
              }
          catch(IOException event){}
       }
   }
else if(e.getSource()==b_update)
   { 显示区.setText(null);
     try {FileInputStream come_in=new FileInputStream("xx.txt");
         ObjectInputStream in=new   ObjectInputStream(come_in);
         Xx_list=(LinkedList)in.readObject();
        }
    catch(ClassNotFoundException event){}
    catch(IOException event){}
    Iterator iter=Xx_list.iterator();
    while(iter.hasNext())
     {   信息 te=(信息)iter.next();
        显示区.append("编号:"+te.编号+"    ");
        显示区.append("姓名:"+te.姓名+"    ");
        显示区.append("类型:"+te.类型+"    ");
        显示区.append("单位地址:"+te.单位地址+"    ");
        显示区.append("职称:"+te.职称+"    ");
        显示区.append("联系电话:"+te.联系电话+"    ");
        显示区.append("邮编:"+te.邮编+"    ");
        显示区.append("邮箱:"+te.邮箱+"    ");
        显示区.append("\n");
     }
   }
   else System.exit(0);
}
}
public class Xxzc
{
public   static void main(String args[])
{
   ShowWin win=new ShowWin();
   win.setSize(800,300);
   win.setVisible(true);
   win.setTitle("信息注册");
   win.addWindowListener(new WindowAdapter()
   {
    public void windowClosing(WindowEvent e)
     {
     System.exit(0);
     }
   });
}
}
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: Java 语言 编程 注册 源码
相关日志:
评论: 0 | 引用: 0 | 查看次数: 2002