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

📄 information.java

📁 用户信息查询
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import java.io.*;
//设置添加对话框
class constructadddialog extends WindowAdapter implements ActionListener
{
	Panel p;
	Panel ps;
	TextField name;
	TextField age;
	TextField birthday;
	TextField QQnumble;
	TextField telephonenumble;
	Button confirm,resert,cancel;
	Choice sex;
	public  void go(){
		Information.adddialog.addWindowListener(this);
		Information.adddialog.setLocation(300,350);
		Information.adddialog.setResizable(false); 
		p=new Panel();
		p.setLayout(new GridLayout(6,2));
		p.add(new Label("姓名:"));
		name=new TextField(8);
		p.add(name);
		p.add(new Label("性别"));
		sex=new Choice();
		sex.add("男");
		sex.add("女");
		p.add(sex);
		p.add(new Label("年龄"));
		age=new TextField(2);
		p.add(age);
		p.add(new Label("生日"));
		birthday=new TextField();
		p.add(birthday);
		p.add(new Label("QQ号码"));
		QQnumble=new TextField();
		p.add(QQnumble);
		p.add(new Label("电话号码"));
		telephonenumble=new TextField();
		telephonenumble.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				if(name.getText().length()!=0){
					JOptionPane.showMessageDialog(Information.adddialog,"添加用户成功");
					savename();
					saveage();
					savebirthday();
					saveQQnumble();
					savetelephonenumble();
					savesex();
				}
				else{
					JOptionPane.showMessageDialog(Information.adddialog,"姓名不能为空?");
				}
			}
		});
		p.add(telephonenumble);
		Information.adddialog.add(p,"Center");
		ps=new Panel();
		//ps.setAlignment(Panel.CENTER);
		confirm=new Button("添加");
		confirm.addActionListener(this);
		ps.add(confirm);
		resert=new Button("重置");
		resert.addActionListener(this);
		ps.add(resert);
		cancel=new Button("关闭");
		cancel.addActionListener(this);
		ps.add(cancel);
		Information.adddialog.add(ps,"South");
		Information.adddialog.pack();
	}

    void savename(){
		try{
			RandomAccessFile fis=new RandomAccessFile("姓名.txt","rw");
			byte b[]=new byte[name.getText().length()];
			b=name.getText().getBytes();
			fis.seek(fis.length());
			fis.write(b);
			fis.write('\n');
			fis.close();
		}
		catch(Exception e){}
	}
	void saveage(){
		try{
			RandomAccessFile fis=new RandomAccessFile("年龄.txt","rw");
			byte b[]=new byte[age.getText().length()];
			b=age.getText().getBytes();
			fis.seek(fis.length());
			fis.write(b);
			fis.write('\n');
			fis.close();
		}
		catch(Exception e){}
	}
	void savebirthday(){
		try{
			RandomAccessFile fis=new RandomAccessFile("生日.txt","rw");
			byte b[]=new byte[birthday.getText().length()];
			b=birthday.getText().getBytes();
			fis.seek(fis.length());
			fis.write(b);
			fis.write('\n');
			fis.close();
		}
		catch(Exception e){}
	}
	void saveQQnumble(){
		try{
			RandomAccessFile fis=new RandomAccessFile("QQ号码.txt","rw");
			byte b[]=new byte[QQnumble.getText().length()];
			b=QQnumble.getText().getBytes();
			fis.seek(fis.length());
			fis.write(b);
			fis.write('\n');
			fis.close();
		}
		catch(Exception e){}
	}
	void savetelephonenumble(){
		try{
			RandomAccessFile fis=new RandomAccessFile("电话号码.txt","rw");
			byte b[]=new byte[telephonenumble.getText().length()];
			b=telephonenumble.getText().getBytes();
			fis.seek(fis.length());
			fis.write(b);
			fis.write('\n');
			fis.close();
		}
		catch(Exception e){}
	}
	void savesex(){
		try{
			RandomAccessFile fis=new RandomAccessFile("性别.txt","rw");
			byte b[]=new byte[sex.getSelectedItem().length()];
			b=sex.getSelectedItem().getBytes();
			fis.seek(fis.length());
			fis.write(b);
			fis.write('\n');
			fis.close();
		}
		catch(Exception e){}
	}
	public void actionPerformed(ActionEvent e){
		Button bt=(Button)e.getSource();
		if(bt==confirm&&name.getText().length()!=0){
			JOptionPane.showMessageDialog(Information.adddialog,"添加用户成功");
			savename();
			saveage();
			savebirthday();
			saveQQnumble();
			savetelephonenumble();
			savesex();
		}
		if(bt==confirm&&name.getText().length()==0)
			JOptionPane.showMessageDialog(Information.adddialog,"姓名不能为空?");
		if(bt==resert){
			name.setText("");
			age.setText("");
			birthday.setText("");
			QQnumble.setText("");
			telephonenumble.setText("");
		}
		if(bt==cancel){
			Information.adddialog.hide();
			name.setText("");
			age.setText("");
			birthday.setText("");
			QQnumble.setText("");
			telephonenumble.setText("");
		}
	}
	
	public void windowClosing(WindowEvent e){
		Information.adddialog.hide();
	}

}

class constructseekdialog extends WindowAdapter implements ActionListener
{
	Panel p;
	TextField tf;
	Button confirm,cancel;
	TextArea ta;
	int lab;
	Dialog seek=Information.seekdialog;
	public void go(){
		seek.addWindowListener(this);
		seek.setResizable(false);
		seek.setLocation(300,350);
		p=new Panel();
		p.add(new Label("请输入姓名:"));
		tf=new TextField(4);
		tf.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				compare();
			}
		});
		p.add(tf);
		confirm=new Button("搜索");
		confirm.addActionListener(this);
		p.add(confirm);
		cancel=new Button("关闭");
		cancel.addActionListener(this);
		p.add(cancel);
		seek.add(p,"North");
		ta=new TextArea();
		ta.setEditable(false);
		seek.add(ta,"Center");
		seek.pack();

	}
	public void windowClosing(WindowEvent e){
		seek.hide();
	}
	public void actionPerformed(ActionEvent e){
		Button bt=(Button)e.getSource();
		if(bt==confirm)
			compare();
		if(bt==cancel)
			seek.hide();

	}
	void compare(){
		try{
			lab=-1;
			FileInputStream fisname=new FileInputStream("姓名.txt");
			FileInputStream fissex=new FileInputStream("性别.txt");
			FileInputStream fisage=new FileInputStream("年龄.txt");
			FileInputStream fisbirthday=new FileInputStream("生日.txt");
			FileInputStream fisQQnumble=new FileInputStream("QQ号码.txt");
			FileInputStream fistelephonenumble=new FileInputStream("电话号码.txt");
			byte bname[]=new byte[fisname.available()];
			byte bsex[]=new byte[fissex.available()];
			byte bage[]=new byte[fisage.available()];
			byte bbirthday[]=new byte[fisbirthday.available()];
			byte bQQnumble[]=new byte[fisQQnumble.available()];
			byte btelephonenumble[]=new byte[fistelephonenumble.available()];
			String allname,allage,allsex,allbirthday,allQQnumble,alltelephonenumble;
			fisname.read(bname);
			fisage.read(bage);
			fissex.read(bsex);
			fisbirthday.read(bbirthday);
			fisQQnumble.read(bQQnumble);
			fistelephonenumble.read(btelephonenumble);
			allname=new String(bname);
			allage=new String(bage);
			allsex=new String(bsex);
			allbirthday=new String(bbirthday);
			allQQnumble=new String(bQQnumble);
			alltelephonenumble=new String(btelephonenumble);
			String sname[]=new String[100];
			String sage[]=new String[100];
			String ssex[]=new String[100];
			String sbirthday[]=new String[100];
			String sQQnumble[]=new String[100];
			String stelephonenumble[]=new String[100];
			for(int i=0;i<100;i++){
				sname[i]="";
				sage[i]="";
				ssex[i]="";
				sbirthday[i]="";
				sQQnumble[i]="";
				stelephonenumble[i]="";
			}
			int kname=0;
			int kage=0;
			int ksex=0;
			int kbirthday=0;
			int kQQnumble=0;
			int ktelephonenumble=0;
			for(int i=0;i<allname.length();i++){
				if(allname.charAt(i)!='\n')
					sname[kname]+=allname.charAt(i);
				else
					kname++;
			}
			for(int i=0;i<allage.length();i++){
				if(allage.charAt(i)!='\n')
					sage[kage]+=allage.charAt(i);
				else
					kage++;
			}
			for(int i=0;i<allsex.length();i++){
				if(allsex.charAt(i)!='\n')
					ssex[ksex]+=allsex.charAt(i);
				else
					ksex++;
			}
			for(int i=0;i<allbirthday.length();i++){
				if(allbirthday.charAt(i)!='\n')
					sbirthday[kbirthday]+=allbirthday.charAt(i);
				else
					kbirthday++;
			}
			for(int i=0;i<allQQnumble.length();i++){
				if(allQQnumble.charAt(i)!='\n')
					sQQnumble[kQQnumble]+=allQQnumble.charAt(i);
				else
					kQQnumble++;
			}
			for(int i=0;i<alltelephonenumble.length();i++){
				if(alltelephonenumble.charAt(i)!='\n')
					stelephonenumble[ktelephonenumble]+=alltelephonenumble.charAt(i);
				else
					ktelephonenumble++;
			}
			
			for(int i=0;i<kname;i++)
				if(sname[i].equals(tf.getText())){
					lab=i;
					break;
			}
			String s="";
			if(lab<kname&&lab>=0)
				s+="姓名:"+sname[lab]+"\n"+"性别:"+ssex[lab]+"\n"+"年龄:"+sage[lab]+"\n"+"生日:"+sbirthday[lab]+"\n"+"QQ号码:"+sQQnumble[lab]+"\n"+"电话号码:"+stelephonenumble[lab];
		
			if(tf.getText().length()==0){
				JOptionPane.showMessageDialog(seek,"姓名不能为空?");
				return;
			}
			else{
				if(lab==-1){
					JOptionPane.showMessageDialog(seek,"该用户不存在?");
					return;
				}
			}
			

			ta.setText(s);
			fisname.close();
			fisage.close();
			fissex.close();
			fisbirthday.close();
			fisQQnumble.close();
			fistelephonenumble.close();
		}
		catch(Exception e){}
	}
}

class constructdeletedialog extends WindowAdapter implements ActionListener
{
	Panel p;
	TextField tf;
	Button confirm,cancel;
	int lab;
	Dialog delete=Information.deletedialog;
	public void go(){
		delete.addWindowListener(this);
		delete.setResizable(false);
		delete.setLocation(300,350);
		p=new Panel();
		p.add(new Label("请输入姓名:"));
		tf=new TextField(4);
		tf.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				compare();
			}
		});
		p.add(tf);
		confirm=new Button("删除");
		confirm.addActionListener(this);
		p.add(confirm);
		cancel=new Button("关闭");
		cancel.addActionListener(this);
		p.add(cancel);
		delete.add(p,"North");
		delete.pack();

	}
	public void windowClosing(WindowEvent e){
		delete.hide();
	}
	public void actionPerformed(ActionEvent e){
		Button bt=(Button)e.getSource();
		if(bt==confirm)
			compare();
		if(bt==cancel)
			delete.hide();

	}
	void compare(){
		try{
			lab=-1;
			FileInputStream fisname=new FileInputStream("姓名.txt");
			FileInputStream fissex=new FileInputStream("性别.txt");
			FileInputStream fisage=new FileInputStream("年龄.txt");
			
			FileInputStream fisbirthday=new FileInputStream("生日.txt");
			
			FileInputStream fisQQnumble=new FileInputStream("QQ号码.txt");
            
			FileInputStream fistelephonenumble=new FileInputStream("电话号码.txt");
			 
			byte bname[]=new byte[fisname.available()];
			byte bsex[]=new byte[fissex.available()];
			byte bage[]=new byte[fisage.available()];
			byte bbirthday[]=new byte[fisbirthday.available()];
			byte bQQnumble[]=new byte[fisQQnumble.available()];
			byte btelephonenumble[]=new byte[fistelephonenumble.available()];
			String allname,allage,allsex,allbirthday,allQQnumble,alltelephonenumble;
			fisname.read(bname);
			fisage.read(bage);
			fissex.read(bsex);
			fisbirthday.read(bbirthday);
			fisQQnumble.read(bQQnumble);
			fistelephonenumble.read(btelephonenumble);
			allname=new String(bname);
			allage=new String(bage);
			allsex=new String(bsex);
			allbirthday=new String(bbirthday);
			allQQnumble=new String(bQQnumble);
			alltelephonenumble=new String(btelephonenumble);
			String sname[]=new String[100];
			String sage[]=new String[100];
			String ssex[]=new String[100];
			String sbirthday[]=new String[100];
			String sQQnumble[]=new String[100];
			String stelephonenumble[]=new String[100];
			for(int i=0;i<100;i++){
				sname[i]="";
				sage[i]="";
				ssex[i]="";
				sbirthday[i]="";
				sQQnumble[i]="";
				stelephonenumble[i]="";
			}
			int kname=0;
			int kage=0;
			int ksex=0;
			int kbirthday=0;

⌨️ 快捷键说明

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