开发者

Java Address Book - Next Steps

开发者 https://www.devze.com 2023-02-22 17:41 出处:网络
I have been asked to create a GUI Address Book. I have created the several different GUI\'s for each screen, for example, Main Method in one class, Main Menu class, Add New Contact class (consisting o

I have been asked to create a GUI Address Book. I have created the several different GUI's for each screen, for example, Main Method in one class, Main Menu class, Add New Contact class (consisting of 13 JTextFields for new contacts), Search 1 class, Search 2 class, Import MUAB class, Export MUAB class, Import VCARD class, and Export VCARD class.

On the Add New Contact GUI, how do I get the data that the user enters for all 13 JTextFields and store it somewhere so that I can use it later to Import and Export in the 2 different formats mentio开发者_Python百科ned above, generate 2 different Searches, and Update Contacts, Delete Contacts and to Show All Contacts in Tabular format?

Any help from anyone is much appreciated!

Thanks in advanced!


You can get the value of the text fields by calling their getText() methods. After this, you will have to store the values (in a database). So you will have to write something like a data layer class which handles DB connection for you. In this class you can write methods to insert, update, search, or delete you address book entries.

For im-/exporting data you need a class which can translate the different formats (read them and extract the data to store it in you database and write the content of your database into the wanted formats)


  • Get values entered in JTextFields by using jTextField.getText() method.
  • Store this values in database.
  • When you have to export this values fetch them from db.

  • To import contact just insert the values in db. [Assuming that you have proper import format and know how to get values from it.]
  • For searching functionality query in db to get appropriate results.
  • For delete/update contact you also have db queries to do this.
  • To show all contacts just retrieve all contacts and display them.

Edit

You can use any db you want to use. To learn about using database in Java see Database-Programming-in-Java-Using-JDBC and O'reilly Java JDBC. Also see wiki - Java_Database_Connectivity.


Edit2

Try something like: Make a global list of contacts which can be accessed by all classes in your app.

List<Contact> contacts = new ArrayList<Contact>();

and in you actionListener of button use: contacts.add(contact);. Now where-ever you want to access data try this:

for (Contact contact : contacts) {
    //--- Do processing with contact.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消