After Mingo's negation, Java Thai again out new works! Mingo Access Code!

Source: Internet
Author: User
Tags addall character classes gettext vars

The last time to do that system is SWING+JDBC realization, helpless by Ming elder brother a negation, database connection completely can not reflect the function of data structure, hey, this is to the younger brother pressure ah. People without pressure not out of oil, after 10 days of efforts, finally Li Gang's address book updated to 1.1 version!

The following are the design ideas, as well as specific reports

————————————————————————————————————————————————————

An experimental report on Li Gang's address book design

--Jiang Jintai 1132 class

1) Topics

Li Gang is a love toss of the people, of course, love tossing the person has a dream, he wants to be China's cover time. No, now personal friends more information, complex, he wanted to make a personal Address book production management software. Just this semester to learn the data structure class, so he is ready to use the data structure knowledge to achieve. and consider using a doubly linked list as a data structure. and established the preliminary requirements:


(1) Each friend information includes name, gender, address, zip code, age, telephone, QQ, account number, birthday, etc.


(2) As a complete system, should have a friendly interface and strong fault tolerance

2) Demand Analysis

First, transport to the relevant data structure Foundation--Double linked list

Second, can not move the database, that is, the need to use the file IO stream, the character information recorded in the relevant files

Third, need to have the basic function of adding and deleting

Four, good interactive interface

Four, better fault-tolerant ability

3) Conceptual Structure design

Characters ={ name, gender, address, zip code, age, Phone, QQ, account number, birthday }

Name is code, phone is code (key)

4) Logical Structure design

One, doubly linked list, specific difficult to achieve, so to develop Lenovo, double-linked table tree--Tree as a collection of data structure (hereinafter referred to as the tree set).

Second, the information is stored in the tree set.

Third, the tree collection to the data file

Iv. file, change data, file---Tree set

5) Physical Structure design

First, the establishment of the data file

Second, the construction of the character class

Third, the construction tree integration as a collection of character classes

Four, well-structured interactive interface

6) system implementation and testing


Simple one package, addresslisttreeset for tree set

The person class contains a collection of character attributes

Showjframe Main interface

DAT is a file for storing people's information

This is the main interface, the left is a jlist surname navigation, below is a function panel, where, by name lookup and by phone number lookup will read the name box and the contents of the phone box

Clicking the navigation box jumps


Add button function, if any one input is empty, will error, support input do not know

Click Down on the bar, click Search by name will be queried

Phone numbers don't do it.


Delete effect, select any, delete, read data after end

7) Advantages and disadvantages self-evaluation

First, AddressList1.1 lost the 1.0 version of the interface beautification, but also reduce the layer of the interface

Second, the lack of modification function, because the implementation of more complex, time is not allowed, so.

Three, I do not make the best use of time, always programming at night

Four, graphical interface and data structure part of the content is not solid, do often want to read, see CSDN, lack of efficiency

8) code show, put code past! Mingo Access Code!

Package Com.friend;import Java.io.serializable;import Java.util.comparator;public class Personclass implements comparable<personclass>,comparator<personclass>,serializable{/** * */private static final long Serialversionuid = -262413201900983336l; String Name,phonecode,sex,address,zip_code,old,qq,blog,birthday;public personclass (String name,string phonecode, String sex,string address,string zip_code,string old,string qq,string blog,string birthday) {this.name=name; THIS.PHONECODE=PHONECODE;THIS.SEX=SEX;THIS.ADDRESS=ADDRESS;THIS.ZIP_CODE=ZIP_CODE;THIS.OLD=OLD;THIS.QQ=QQ; This.blog=blog;this.birthday=birthday;} Public Personclass (String element[]) {name=element[0];p Honecode=element[1];sex=element[2];address=element[3];zip_ CODE=ELEMENT[4];OLD=ELEMENT[5];QQ=ELEMENT[6];BLOG=ELEMENT[7];BIRTHDAY=ELEMENT[8]; System.out.print (birthday);} Public object[] ToArray () {object[] VARs = new Object[9];vars[0]=name;vars[1]=this.phonecode;vars[2]=this.sex;vars[3] =this.address;vars[4]=this.zip_code;vars[5]=this.old;vars[6]=this.qq;vars[7]=this.blog;vars[8]=this.birthday;return VARs;} Public String Index () {return this.name.substring (0, 1);} @Overridepublic int compareTo (Personclass o) {//TODO auto-generated method stub if (this.name!=o.name) {return This.name.compareTo ( O.name);} if (This.phonecode!=o.phonecode) {return this.phonecode.compareTo (O.phonecode);} if (this.sex!=o.sex) {return this.sex.compareTo (o.sex);} if (this.address!=o.address) {return this.address.compareTo (o.address);} if (This.zip_code!=o.zip_code) {return this.zip_code.compareTo (O.zip_code);} if (this.old!=o.old) {return this.old.compareTo (o.old);} if (THIS.QQ!=O.QQ) {return this.qq.compareTo (O.QQ);} if (this.blog!=o.blog) {return this.blog.compareTo (o.blog);} Return This.birthday.compareTo (O.birthday);} @Overridepublic int Compare (Personclass O1, Personclass O2) {//TODO auto-generated method stub return O1.name.compareTo (O2.name);} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public String Getphonecode () {return phonecode;} Public VOID Setphonecode (String phonecode) {this.phonecode = Phonecode;} Public String Getsex () {return sex;} public void Setsex (String sex) {this.sex = sex;} Public String getaddress () {return address;} public void setaddress (String address) {this.address = address;} Public String Getzip_code () {return zip_code;} public void Setzip_code (String zip_code) {this.zip_code = Zip_Code;} Public String Getold () {return old;} public void Setold (String old) {this.old = old;} Public String getqq () {return QQ;} public void Setqq (String qq) {this.qq = QQ;} Public String Getblog () {return blog;} public void Setblog (String blog) {this.blog = blog;} Public String Getbirthday () {return birthday;} public void Setbirthday (String birthday) {this.birthday = birthday;}} Class Indexcomparator implements Comparator<personclass>{public int compare (Personclass F1, Personclass F2) { Return F1.index (). CompareTo (F2.index ());}} Class Codecomparator implements Comparator<personclass>{public int compare (Personclass F1, Personclass F2) {return f1.phonecode.compareTo (F2.phonecode);}} 

Package Com.friend;import Java.io.fileinputstream;import Java.io.fileoutputstream;import java.io.IOException; Import Java.io.objectinputstream;import Java.io.objectoutputstream;import Java.util.comparator;import  Java.util.iterator;import Java.util.treeset;public class Addresslisttreeset extends treeset<personclass>{/** * */private static final Long serialversionuid = -673031400092308095l;private String filename;public addresslisttreeset ( String filename) {super (); This.filename=filename;this.readfromfile ();} public void ReadFromFile () {try{fileinputstream fin = new FileInputStream (this.filename); ObjectInputStream objin=new ObjectInputStream (Fin); while (true) Try{this.add ((Personclass) objin.readobject ());} catch (Exception e) {break;} Objin.close (); Fin.close ();} catch (IOException IoE) {System.out.print ("set is Empty");}} public void WriteToFile () {Try{fileoutputstream fout = new FileOutputStream (this.filename); ObjectOutputStream objout= New ObjectOutputStream (Fout); iterator<personclass>it=this.Iterator (); while (It.hasnext ()) {Personclass f=it.next (); System.out.print (F.tostring ()); Objout.writeobject (f);} Objout.close (); Fout.close (); System.out.print ("write Success");} catch (IOException IoE) {System.out.print (IoE);}} Public Personclass Search (Personclass x,comparator<personclass> c) {iterator<personclass>it= This.iterator (); while (It.hasnext ()) {Personclass f= it.next (); if (C.compare (f,x) ==0) return F;} return null;}}

Package Com.friend;import Java.awt.gridlayout;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.awt.event.windowevent;import Java.awt.event.windowlistener;import Java.util.comparator;import Java.util.iterator;import Javax.swing.defaultcomboboxmodel;import Javax.swing.defaultlistmodel;import Javax.swing.jbutton;import Javax.swing.jcombobox;import Javax.swing.JFrame; Import Javax.swing.jlabel;import javax.swing.jlist;import Javax.swing.joptionpane;import Javax.swing.JPanel;import Javax.swing.jscrollpane;import Javax.swing.jsplitpane;import Javax.swing.jtable;import Javax.swing.JTextField; Import Javax.swing.listselectionmodel;import Javax.swing.event.listselectionevent;import Javax.swing.event.listselectionlistener;import Javax.swing.table.defaulttablemodel;public class ShowJFrame extends JFrame implements listselectionlistener,actionlistener,windowlistener{/** * */private static final long Serialversionuid = -7933446592390771790l;private AddresslisttreeseT book;private jlist<string> list;private defaultlistmodel<string> listmodel;private JTable table;private DefaultTableModel tablemodel;private jcombobox<object> combobox_name;private DefaultComboBoxModel<Object > combomodel;private jtextfield text_code;private jtextfield text_sex;private JTextField text_address;private JTextField text_zipcode;private JTextField text_old;private jtextfield text_qq;private JTextField text_blog;private JTextField text_birth;public showjframe (String filename) {super ("Contacts"); This.setbounds (250,100,941,362); This.setdefaultcloseoperation (Exit_on_close); This.addwindowlistener (this); JSplitPane split_h=new JSplitPane (jsplitpane.horizontal_split); split_h.setdividerlocation (40); This.getcontentpane (). Add (Split_h); JSplitPane split_v=new JSplitPane (jsplitpane.vertical_split); split_v.setdividerlocation; this.book= New Addresslisttreeset (filename); this.listmodel=new defaultlistmodel<string> (); This.listModel.addElement ("All" ); this.list=newJlist<string> (Listmodel); This.list.setSelectionMode (listselectionmodel.single_selection); This.list.addListSelectionListener (this); Split_h.add (new JScrollPane (this.list)); Split_h.add (SPLIT_V); String[] columns={"name", "Phone number", "gender", "address", "postcode", "Age", "QQ", "Account Number", "Birthday"//name,phonecode,sex,address,zip_code,old,qq, Blog,birthday};this.tablemodel=new DefaultTableModel (columns,0); this.table=new JTable (TableModel); This.list.setSelectedIndex (0); Split_v.add (new JScrollPane (table)); JPanel friendpanel=new JPanel (New GridLayout (2,1)); Split_v.add (Friendpanel); JPanel panels[]={new JPanel (), New JPanel ()};for (int i=0;i<panels.length;i++) {friendpanel.add (panels[i]);} Panels[0].add (New JLabel (columns[0)); this.combomodel=new defaultcomboboxmodel<object> (); combobox_name=new Jcombobox<object> (This.combomodel); combobox_name.setenabled (true); Combobox_name.seteditable (true);p Anels [0].add (Combobox_name);p Anels[0].add (New JLabel (columns[1])); This.text_code=new JTextField ("12345678901", 12); Panels[0].add(Text_code);p Anels[0].add (New JLabel (columns[2)), this.text_sex=new JTextField ("Male", 2);p Anels[0].add (text_sex); Panels[0].add (New JLabel (Columns[3])), This.text_address=new JTextField ("12345678901",;p Anels[0].add (text_ Address);p Anels[0].add (New JLabel (columns[4)), This.text_zipcode=new JTextField ("521000", 6);p Anels[0].add (text_ ZipCode);p Anels[0].add (New JLabel (columns[5)), This.text_old=new JTextField ("2");p Anels[0].add (text_old); Panels[0].add (New JLabel (Columns[6])), This.text_qq=new JTextField ("12345678901",;p Anels[0].add (TEXT_QQ); Panels[0].add (New JLabel (Columns[7])), This.text_blog=new JTextField ("12345678901",;p Anels[0].add (Text_blog); Panels[0].add (New JLabel (Columns[8])) this.text_birth=new JTextField ("12345678901",;p anels[0].add (Text_birth) ; This.addindex (); String buttonstr[]={"Add", "Find by name", "Find by phone number", "Delete Line"}; JButton buttons[]=new jbutton[buttonstr.length];for (int i=0;i<buttons.length;i++) {buttons[i]=new JButton ( Buttonstr[i]);p Anels[1].add (Buttons[i]); buttons[i].addactiOnlistener (this);} This.setvisible (TRUE);} private void Addindex () {iterator<personclass>it=this.book.iterator (); while (It.hasnext ()) {String indexstr= It.next (). Index (), if (!this.listmodel.contains (INDEXSTR)) {this.listModel.addElement (INDEXSTR); This.comboModel.addElement (INDEXSTR);}}} @Overridepublic void windowopened (WindowEvent e) {} @Overridepublic void windowclosing (WindowEvent e) { This.book.writeToFile (); System.out.print ("Write program Start");} @Overridepublic void windowclosed (WindowEvent e) {} @Overridepublic void windowiconified (WindowEvent e) {}@ overridepublic void Windowdeiconified (WindowEvent e) {} @Overridepublic void windowactivated (WindowEvent e) {}@ overridepublic void windowdeactivated (WindowEvent e) {} @Overridepublic void actionperformed (ActionEvent e) {String name = (String) combobox_name.getselecteditem (); String Code=text_code.gettext (); String Sex=text_sex.gettext (); String Address=text_address.gettext (); String Zipcode=text_zipcode.gettext (); String Old=text_old.gettext (); String QQ=TEXT_QQ. GetText (); String Blog=text_blog.gettext (); String Birth=text_birth.gettext (), if (E.getactioncommand (). Equals ("Add")) {Personclass F = new Personclass (Name,code, Sex,address,zipcode,old,qq,blog,birth), if (name==null) {Joptionpane.showmessagedialog (this, "Cannot add name to empty object");} else if (!name.equals ("")) {This.book.add (f); String Surname=f.index (), if (List.getselectedvalue (). Equals (surname)) Tablemodel.addrow (F.toarray ()); Else{if (! Listmodel.contains (surname)) {listmodel.addelement (surname); Combomodel.addelement (surname);} List.setselectedvalue (surname, True);}} else {Joptionpane.showmessagedialog (this, "Cannot add name empty string or Duplicate object" +f.tostring ());}} if (!this.book.isempty () &&e.getactioncommand (). EndsWith ("find")) {for (int i=tablemodel.getrowcount () -1;i >=0;i--) This.tableModel.removeRow (i), if (E.getactioncommand () equals ("Find by Name")) This.addall (New Personclass ( Name, "," "," "," "," "," "," "," "), new Personclass (Name," "," "," "," "," "," "," "," "")); Else{personclass find= This.book.search (New Personclass ("", Code, "", "", "", "", "", "", ""), newCodecomparator ()); if (find!=null) This.tableModel.addRow (Find.toarray ());} return;} if (E.getactioncommand (). Equals ("Delete Row")) {if (This.book.isEmpty ()) Joptionpane.showmessagedialog (this, "The table is empty, you cannot delete the data item. "); Else{int I=table.getselectedrow (); if (i==-1) Joptionpane.showmessagedialog (this, select data item); Else{name= (String) Table.getvalueat (i, 0); int yes=joptionpane.showconfirmdialog (null, "delete \" "+name+" \ "line?"); if (yes==0) {code= (string) table.getvalueat (i, 1), sex= (String) table.getvalueat (I, 2); address= (String) Table.getvalueat (i, 3); zipcode= (String) table.getvalueat (I, 4), old= (String) table.getvalueat (I, 5); qq= (String) Table.getvalueat (i, 6); blog= (String) table.getvalueat (I, 7); birth= (String) table.getvalueat (I, 8); System.out.print (birth); Personclass f=new Personclass (Name,code,sex,address,zipcode,old,qq,blog,birth); This.book.remove (f); Tablemodel.removerow (i); if (This.book.search (F, New Indexcomparator ()) ==null) {listmodel.removeelement (F.index ()); Combomodel.removeelement (F.index ());}}}}} @Overridepublic void ValueChanged (LIstselectionevent e) {string surname= (String) list.getselectedvalue (); if (!this.book.isempty () &&surname!= Null&&surname!= "") {for (int i= this.tableModel.getRowCount () -1;i>=0;i--) This.tableModel.removeRow (i); if (surname== "all") this.addall (); Else This.addall (New Personclass (surname, "", "", "", "", "", "", "", ""), new Indexcomparator ());}} private void AddAll (Personclass friend,comparator<personclass> c) {iterator<personclass> it = This.book.iterator (); while (It.hasnext ()) {Personclass f= it.next (); if (c==null| | C.compare (friend,f) ==0) This.tableModel.addRow (F.toarray ());}} private void AddAll () {this.addall (null,null);} public static void Main (String args[]) {new Showjframe ("e:\\ workbooks \\AddressList1.1\\src\\data\\ Address Book. dat");}}



After Mingo's negation, Java Thai again out new works! Mingo Access Code!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.