最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實現(xiàn)通訊錄管理系統(tǒng)

 更新時間:2020年07月24日 15:03:01   作者:PayneWoo  
這篇文章主要為大家詳細介紹了java實現(xiàn)通訊錄管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java實現(xiàn)通訊錄管理系統(tǒng)的具體代碼,供大家參考,具體內容如下

完成項目的流程:

1.根據(jù)需求,確定大體方向
2.功能模塊分析
3.界面實現(xiàn)
4.功能模塊設計
5.coding
6.代碼測試

下面是源代碼:

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.text.html.HTMLDocument.Iterator;


class Infro{
 public String id;
 public String name;
 public String sex;
 public String address;
 public String e_mail;
 public String phoneNumber;
 static int index = 0;
 static ArrayList<Infro> list = new ArrayList();
 static int len = list.size();
 //構造函數(shù)
 public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){
 this.id = id;
 this.name = name;
 this.sex = sex;
 this.address = address;
 this.e_mail = e_mail;
 this.phoneNumber = phoneNumber;
 }
 public String toString(){
 return "編號:"+id+" 姓名:"+name+" 性別:"+sex+" 通訊地址:"+address+" 郵箱地址:"+e_mail+" 電話:"+phoneNumber;
 }

 /**
 * 添加功能
 **/
 public static void addFunction(){//添加功能
 Infro infro = new Infro("","","","","","");
 System.out.println("請輸入添加的數(shù)據(jù):");
 Scanner in = new Scanner(System.in);
 System.out.println("輸入編號:");
 infro.id = in.next();
 System.out.println("輸入姓名:");
 infro.name = in.next();
 System.out.println("輸入性別:");
 infro.sex = in.next();
 System.out.println("輸入通訊地址:");
 infro.address = in.next();
 System.
 out.println("輸入郵箱地址:");
 infro.e_mail = in.next();
 System.out.println("輸入電話:");
 infro.phoneNumber = in.next();
 list.add(index,infro);
 index++;
 if(list.isEmpty()){
 System.out.println("數(shù)據(jù)添加失敗啦");
 }else{
 System.out.println("數(shù)據(jù)添加成功啦");
 len++;//list集合長度加一
// System.out.println(list.get(0).toString());
 }

 }
// public static void deleteFunction(){//刪除功能
// System.out.println("輸入要刪除的聯(lián)系人的編號");
// Scanner in_2 = new Scanner(System.in);
// String d1 = in_2.nextLine();
// for(int a= 0; a<len;a++){
// if(d1.equals(list.get(a).id)){
// list.remove(list.get(a));
// len --; 
// }
// }
// }
 /**
 * 刪除功能
 **/
 public static void deleteFunction(){
 System.out.println("輸入要刪除的聯(lián)系人的編號");
 Scanner in_2 = new Scanner(System.in);
 String d1 = in_2.nextLine();
 java.util.Iterator<Infro> it = list.iterator();
 while (it.hasNext()){
 Infro infro = it.next();
 if (infro.id.equals(d1)){
 it.remove();
 --index;//一定要加這個,否則當做了刪除操作再做添加操作的時候會出現(xiàn)異常(類似于指針,棧)
 System.out.println("刪除完畢"+"此時通訊錄記錄條數(shù)為:" + --len);
 }
 }
 }
 /**
 * 修改功能
 **/
 public static void reditFunction(){
 System.out.println("輸入要修改的通訊錄的Id");
 Scanner in_r = new Scanner(System.in);
 String r1 = in_r.nextLine();
 for(int a = 0; a < len;a++){
 if(r1.equals(list.get(a).id)){
 System.out.println("輸入修改后的姓名:");
 String name_1 = in_r.next();
 list.get(a).name = name_1;
 System.out.println("輸入修改后的性別:");
 String sex_1 = in_r.next();
 list.get(a).sex = sex_1;
 System.out.println("輸入修改后的通訊地址:");
 String address_1 = in_r.next();
 list.get(a).address = address_1;
 System.out.println("輸入修改后的郵箱地址:");
 String e_mail_1 = in_r.next();
 list.get(a).e_mail = e_mail_1;
 System.out.println("輸入修改后的電話:");
 String phoneNumber_1 = in_r.next();
 list.get(a).phoneNumber = phoneNumber_1;
 System.out.println("數(shù)據(jù)修改完畢");
 }
 }
 }
 /**
 * 查詢功能
 **/
 public static void searchFunction() throws Exception{//查詢功能
 System.out.println("請輸入要查詢的姓名:");
 Scanner in_1 = new Scanner(System.in);
 String s1=in_1.nextLine();
 for(int a= 0; a<len;a++){//切記,,這里不能用a<=list.seze(),否則會數(shù)組越界異常
 if(s1.equals(list.get(a).name)){
 System.out.println(list.get(a).toString());
 }
 }
 }

 /**
 * 顯示功能
 **/
 public static void showFunction(){
 for(int i = 0 ;i<len;i++){
 System.out.println(list.get(i).toString());
 }
 }
 /**
 * 保存功能
 **/
 public static void writeFunction() throws IOException{
 FileWriter writer = new FileWriter("通訊錄管理.txt");
 for(int i = 0 ;i<len;i++){
 String []strwriter = new String[len];
 strwriter[i]=list.get(i).toString();
 writer.write(strwriter[i]);
 writer.write("\r\n");
 System.out.println("成功寫入一行數(shù)據(jù)到 通訊錄管理.txt 中");
 }
 writer.close();//關閉寫入流,釋放資源
 }
 /**
 * 讀取功能
 **/
 public static void readFunction() throws IOException{
 FileReader reader = new FileReader("通訊錄管理.txt");
 BufferedReader br = new BufferedReader(reader);
 String str;
 while((str = br.readLine()) != null){//每次讀取一行文本,判斷是否到達文件尾
 System.out.println(str);
 }
 br.close();
 }
}


public class Demo extends JFrame {

 /**
 * 界面設計
 **/
 public Demo(){
 Container c = getContentPane(); //定義一個頂級容器c
 JPanel jp = new JPanel(); //新建JPanel面板--jp
 JButton button1 = new JButton("新建聯(lián)系人");
 JButton button2 = new JButton("刪除聯(lián)系人");
 JButton button3 = new JButton("編輯聯(lián)系人");
 JButton button4 = new JButton("查找聯(lián)系人");
 JButton button5 = new JButton("顯示所有聯(lián)系人");
 JButton button6 = new JButton("保存聯(lián)系人到本地");
 JButton button7 = new JButton("讀取本地聯(lián)系人");
 jp.setLayout(new GridLayout(2,4,5,5));//新建網(wǎng)格布局管理器(行數(shù),列數(shù),組件間的水平垂直間距)
 jp.add(button1);
 jp.add(button2);
 jp.add(button3);
 jp.add(button4);
 jp.add(button5);
 jp.add(button6);
 jp.add(button7);
 c.add(jp);//將JPanel面板jp添加到頂級容器c中
 setSize(600,500);
 setTitle("*通 訊 錄 管 理 系 統(tǒng)*");
 setVisible(true);
 setResizable(false);//窗體大小由程序員決定,用戶不能自由改變大小
 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


 /**
 *按鍵響應
 * 
 **/
 button1.addActionListener(new ActionListener(){//添加功能實現(xiàn)
 public void actionPerformed(ActionEvent arg0){
 Infro.addFunction();
 }
 });
 button2.addActionListener(new ActionListener(){//刪除功能實現(xiàn)
 public void actionPerformed(ActionEvent arg0){
 Infro.deleteFunction();
 }
 });
 button3.addActionListener(new ActionListener(){//修改功能實現(xiàn)
 public void actionPerformed(ActionEvent arg0){
 Infro.reditFunction();
 }
 });
 button4.addActionListener(new ActionListener(){//查詢功能實現(xiàn)
 public void actionPerformed(ActionEvent arg0){
 try {
 Infro.searchFunction();
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }
 });
 button5.addActionListener(new ActionListener(){//顯示功能實現(xiàn)
 public void actionPerformed(ActionEvent arg0){
 Infro.showFunction();
 }
 });
 button6.addActionListener(new ActionListener(){//保存功能實現(xiàn)
 public void actionPerformed(ActionEvent arg0){
 try {
 Infro.writeFunction();
 } catch (IOException e) {
 e.printStackTrace();
 }
 }
 });
 button7.addActionListener(new ActionListener(){//讀取功能實現(xiàn)
 public void actionPerformed(ActionEvent arg0){
 try {
 Infro.readFunction();
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 }
 });
 }

 public static void main(String[] args) {
 // TODO Auto-generated method stub
 new Demo();
 Infro a = new Infro("", "", "", "", "", "");
 }

}

ps:在用List集合的時候,遇到了一些小問題,這些小問題我在代碼里有注釋,希望以后不要再犯這種問題。

關于管理系統(tǒng)的更多內容請點擊《管理系統(tǒng)專題》進行學習

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • java連接hdfs ha和調用mapreduce jar示例

    java連接hdfs ha和調用mapreduce jar示例

    這篇文章主要介紹了Java API連接HDFS HA和調用MapReduce jar包,需要的朋友可以參考下
    2014-03-03
  • Spring Cloud 配置中心內容加密的配置方法

    Spring Cloud 配置中心內容加密的配置方法

    這篇文章主要介紹了Spring Cloud 配置中心內容加密的配置方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-06-06
  • MybatisPlus操作符和運算值詳解

    MybatisPlus操作符和運算值詳解

    在前端到后端的數(shù)據(jù)傳遞中,處理動態(tài)運算條件是一個常見的需求,本文介紹了如何在MybatisPlus中處理運算符和運算值的動態(tài)拼接問題,感興趣的朋友一起看看吧
    2024-10-10
  • Java并發(fā)之BlockingQueue的使用

    Java并發(fā)之BlockingQueue的使用

    這篇文章主要介紹了Java并發(fā)之BlockingQueue的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • java實現(xiàn)桌球游戲

    java實現(xiàn)桌球游戲

    這篇文章主要為大家詳細介紹了java實現(xiàn)桌球游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • Spring Boot2.0使用Spring Security的示例代碼

    Spring Boot2.0使用Spring Security的示例代碼

    這篇文章主要介紹了Spring Boot2.0使用Spring Security的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • Java代理模式實例分析

    Java代理模式實例分析

    這篇文章主要介紹了Java代理模式,結合實例形式對比分析了java代理模式的使用方法與相關操作技巧,需要的朋友可以參考下
    2019-07-07
  • 詳解Spring Boot實戰(zhàn)之Filter實現(xiàn)使用JWT進行接口認證

    詳解Spring Boot實戰(zhàn)之Filter實現(xiàn)使用JWT進行接口認證

    本篇文章主要介紹了詳解Spring Boot實戰(zhàn)之Filter實現(xiàn)使用JWT進行接口認證,具有一定的參考價值,有興趣的可以了解一下
    2017-07-07
  • Spring Boot開啟的2種方式詳解

    Spring Boot開啟的2種方式詳解

    這篇文章主要介紹了Spring Boot開啟的2種方式詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • java 在file的尾部添加數(shù)據(jù)的兩種方法總結

    java 在file的尾部添加數(shù)據(jù)的兩種方法總結

    這篇文章主要介紹了java 在file的尾部添加數(shù)據(jù)的兩種方法總結的相關資料,這里提供了兩種在file尾部添加數(shù)據(jù)的方法,希望能幫助到大家,需要的朋友可以參考下
    2017-09-09

最新評論

石台县| 林甸县| 双柏县| 赫章县| 龙岩市| 嘉善县| 叶城县| 阜南县| 化州市| 木里| 灯塔市| 沾化县| 丰县| 昭觉县| 淅川县| 吴桥县| 五家渠市| 彩票| 陈巴尔虎旗| 奈曼旗| 文成县| 赣榆县| 鹿邑县| 拉萨市| 黑水县| 南靖县| 九江县| 台北市| 镇原县| 东莞市| 山东省| 防城港市| 印江| 札达县| 平罗县| 巴南区| 措美县| 商城县| 新郑市| 惠东县| 中方县|