java 人员信息查看程序

三个文件:
public class Person {

	private String name;
	private String memo;
	private int age;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getMom() {
		return memo;
	}
	public void setMom(String mom) {
		this.memo = mom;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String toString(){
		return "the person' information is:"+name+"\n"+memo+"\n"+age;
	}
}
import java.util.*;
import java.io.*;
public class ReadPersons {
	public static Vector getInfo(){
		Vector v =new Vector();
		
		try{
			File f =new File("info.txt");
			FileReader fr = new FileReader(f);
			BufferedReader br = new BufferedReader(fr);
			String s = br.readLine();
			while(s!=null){
				Person p =new Person();
				p.setName(s);
				s=br.readLine();
				p.setMom(s);
				s=br.readLine();
				p.setAge(Integer.parseInt(s));
				v.add(p);
				s=br.readLine();
			}
			br.close();
			fr.close();
		}catch(IOException e)
		{
			e.printStackTrace();
		}
		return v;
	}
	
}

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

import javax.swing.*;
public class GuiView extends JFrame implements ActionListener {
	public JTextField tf;
	public JLabel  l1;
	public JLabel l2;
	public JLabel l3;
	public JButton jb1;
	public JButton jb2;
	public int jb1flg = 2;
	public int jb2flg = 0;
	Vector v = ReadPersons.getInfo();
	Person p0;
	public GuiView(){
		tf = new JTextField("请点击按钮读取人员信息数据库");
		tf.setEditable(false);
		l1 = new JLabel("姓名:");
		l2 = new JLabel("名言:");
		l3 = new JLabel("年龄:");
		jb1 = new JButton("上一条");
		jb1.addActionListener(this);
		jb1.setActionCommand("上一条");
		
		jb2 = new JButton("下一条");
		jb2.addActionListener(this);
		jb2.setActionCommand("下一条");
		
		JPanel p1 =new JPanel(new GridLayout(3,1));
		p1.add(l1);
		p1.add(l2);
		p1.add(l3);
		
		JPanel p2 = new JPanel();
		p2.add(jb1);
		p2.add(jb2);
		
		this.add(tf,"North");
		this.add(p1);
		this.add(p2,"South");
		
		this.setTitle("人员参看信息程序");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(400, 400);
		this.setLocation(300, 300);
		this.setVisible(true);
		
	}
	public static void main(String[] args) {
		new GuiView();

	}
	public void actionPerformed(ActionEvent e){
		String s =e.getActionCommand();
		if(s.equals("上一条")){
			p0=(Person)v.get(jb1flg);
			jb1flg=(jb1flg==0)?2:(jb1flg-1);
			l1.setText(p0.getName());
			l2.setText(p0.getMom());
			l3.setText(""+p0.getAge());
			System.out.println(p0.toString());
			
		}else if(s.equals("下一条")){
			p0=(Person)v.get(jb2flg);
			jb2flg=(jb2flg+1)%3;
			l1.setText(p0.getName());
			l2.setText(p0.getMom());
			l3.setText(""+p0.getAge());
			System.out.println(p0.toString());
		}
		
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值