简易通讯录系统(Java)

一、界面展示

1.主界面

简易通讯录系统(Java)_第1张图片

 2.存入联系人

使用方法:输入信息点击确定即表示存入成功

简易通讯录系统(Java)_第2张图片简易通讯录系统(Java)_第3张图片

3.查询联系人

简易通讯录系统(Java)_第4张图片简易通讯录系统(Java)_第5张图片

简易通讯录系统(Java)_第6张图片

 二、代码展示

 1.Txlmain类:主要用于构建主界面以及事件跳转处理

package Tongxunlu;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Txlmain {
	public static void main(String[] args) {
		JFrame frame = new JFrame("个人通讯录");
		Container con=frame.getContentPane();
		con.setLayout(new FlowLayout());
		JLabel title=new JLabel("个人通讯录");
		Font font=new Font("TimersRoman",Font.ITALIC,40);
		title.setFont(font);
		title.setBounds(130, 20, 300, 60);
		frame.add(title);
		
		JButton b1=new JButton("添加联系人");
		JButton b2=new JButton("查找联系人");
		JButton b3=new JButton("退出");
		
		con.add(b1);
		con.add(b2);
		con.add(b3);
		
		//事件处理
		Txl2 txl=new Txl2();
		b1.addActionListener(txl);
		b2.addActionListener(txl);
		b3.addActionListener(txl);
		
		frame.setSize(300,150);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}

2.Txl1:用于存储输入的联系人信息

package Tongxunlu;


public class Txl1{
	private String name;
	private String number;
	private String bianma;
	private String address;
		
	Txl1(String name,String number,String bianma,String address){
		this.name=name;
		this.number=number;
		this.bianma=bianma;
		this.address=address;
	}
	public String Name(){
		return name;
	}
	public String Number(){
		return number;
	}
	public String Bianma(){
		return bianma;
	}
	public String Address(){
		return address;
	}
}		
	

3.Txl:构建具体的事件处理过程

package Tongxunlu;

import java.awt.Button;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Txl2 implements ActionListener {
	String name;
	String bianma;
	String number;
	String address;
	String nn;
	Scanner input=new Scanner(System.in);
	private int num=0;int i;
	Txl1[] r = new Txl1[100];
	JTextField jt1,jt2,jt3,jt4,jjj;
	
	public void actionPerformed(ActionEvent e) {
		String butname1=e.getActionCommand();
		if(butname1.equals("添加联系人")) {
			final JDialog c= new JDialog();
			c.setTitle("添加联系人");
			c.setLocation(100,100);
			c.setSize(300, 300);
			c.setLayout(new FlowLayout());
			
			JLabel jl1=new JLabel("姓名:");
			jt1=new JTextField("");
			jt1.setPreferredSize(new Dimension(200,30));
			JPanel p1=new JPanel();
			p1.add(jl1);p1.add(jt1);
			
			JLabel jl2=new JLabel("电话:");
			jt2=new JTextField();
			jt2.setPreferredSize(new Dimension(200,30));
			JPanel p2=new JPanel();
			p2.add(jl2);p2.add(jt2);
			
			JLabel jl3=new JLabel("邮编:");
			jt3=new JTextField();
			jt3.setPreferredSize(new Dimension(200,30));
			JPanel p3=new JPanel();
			p3.add(jl3);p3.add(jt3);
			
			JLabel jl4=new JLabel("地址:");
			jt4=new JTextField();
			jt4.setPreferredSize(new Dimension(200,30));
			JPanel p4=new JPanel();
			p4.add(jl4);p4.add(jt4);
			
			c.add(p1);
			c.add(p2);
			c.add(p3);
			c.add(p4);
			
			Button but1=new Button("确认");
			Button but2=new Button("退出");
			
			but1.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					// TODO Auto-generated method stub
					name=jt1.getText();
					number=jt2.getText();
					bianma=jt3.getText();
					address=jt4.getText();
			    	r[num]=new Txl1(name,number,bianma,address);
			    	num++;
			    		
			    	}
			});
			but2.addActionListener(new ActionListener(){
				@Override
				public void actionPerformed(ActionEvent e) {
					// TODO Auto-generated method stub
					c.setVisible(false);//退出当前界面
					
					}
			});
			c.add(but1);
			c.add(but2);
			c.setVisible(true);
		}
		else if(butname1.equals("查找联系人")) {
			
			JDialog d= new JDialog();
			d.setTitle("查找联系人");
			d.setLocation(100,100);
			d.setSize(300, 120);
			d.setLayout(new FlowLayout());
			
			JLabel jj=new JLabel("请输入需要查找联系人姓名:");
			jjj=new JTextField();
			jjj.setPreferredSize(new Dimension(100,30));
			JPanel pp=new JPanel();
			pp.add(jj);pp.add(jjj);
			
			
			Button but3=new Button("查找");
			but3.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e) {
					// TODO Auto-generated method stub
					int n=0;
					nn=jjj.getText();
					for(i=0;i

 

 

 

 

你可能感兴趣的:(笔记,java,开发语言)