Monday, February 14, 2011

Java Swing applications -- Telephone and Address Book -- II

Implementation:


The Telephone Book application is now designed and we need to just put the coding for that. We already know which objects in swing package are used as the components in the panels for the application. For example, we have mentioned in the last post about some components such as Drop-down list (JComboBox), Labels for the appropriate components(JLabel), Buttons (JButton), Text-Boxes (JTextBox), Scroll Panes (JScrollPane), Results displayed in Tables (JTable), Confirmation of the results through Dialogs (JDialog) etc.

The Front end is Java Swing while the application has a database connectivity with MS Access database. As mentioned in the previous post, there is only one table in the database. The coding is done in two packages: 
  1. TeleAddress package for Component design and Action listeners &
  2. dao package for accessing database from the MS Access database through JDBC API
In all the classes, the constructors play a key role with initializing the frame window processing purposes. Mouse action listeners are applied to the buttons in the interface that interacts with the user, most of them being applied when the user clicks the mouse.

The confirmation dialogs are present in a separate class, named Dialogs with separate dialogs for contact creation, updating contacts and contact-deletion. The Dialogs class contains the following:
  1. Two Constructors -- one for Deletion and the other for Updation / Addition of contacts
  2. dialog( ) and deldialog( ) functions for processing one of the two constructors.
The TelephoneBook class in TeleAddress package is the main class in the application and binds all the classes together. The TelephoneBook class contains the following:
  1. All the Interface-Components such as Buttons, Drop-down lists, Text-Boxes,Labels,Tables etc. are defined in this class.
  2. 5 Panel functions for adding the components into each panel.
  3. A Constructor having function calls to the Action-listeners.
  4. A function named initComponents( ) for the lay-out of components.
  5. All Action-listeners for all the buttons such as Create, Delete, Update, Refresh, Cancel etc.
The SearchTable class allows the user to view the results in a table in a different Frame window. The Database class consists of all the database-connections, where we use the JDBC-ODBC Bridge Driver for connecting to MS Access. The static methods in this class are used for every database operation being done in the application. The dao package makes use of PreparedStatement and Statement for database query executions. The Database connectivity with MS Access can be done as shown clearly in these posts as part 1, part 2 and part 3. The dao package has the data access objects listed below:
  1. Database class for Database connection.
  2. AddDAO class for insertion of new contact into the database table.
  3. DeleteDAO class for deletion of contact records from the database table.
  4. OtherDAO class to get all the records from the database table
  5. SearchDAO class to facilitate searching upon inputs given in the Search and Delete panels.
  6. UpdateDAO class for updating contact details.
The documentation for the classes of this application have been automatically generated by NetBeans IDE through Javadocs which can be downloaded here.

Installation and Configuring the application:

Pre-requisites:
  1. The system should have Java (JDK and JRE) installed on your system, which can be downloaded from this page.
  2. The system should have Microsoft Office Access DBMS.
Configuring and Installation:
  1. Invoke Control Panel -- Administrative Tools -- Data Sources (ODBC). Go to UserDSN tab and click on Add button.
  2. Select Microsoft Access Driver (*.mdb, *.accdb) and click on Finish button.
  3. Give the Data Source Name as TeleAddressBook and select the Database Select button and give the path of the database file which can be downloaded from here. After selecting the .accdb file, click OK. Any doubts regarding the configuration of DSN (Data Source Name) can be clarified with the tutorial specified previously at this post with screen-shots.
  4. Download the JAR file which can be downloaded here.
  5. After configuring the DSN and downloading the JAR file, double-click on the JAR file to invoke the application. If its not invoked with the double-click then open Command-Prompt and type the one specified as: java -jar "/* Complete Path of the JAR file */"

    No comments:

    Post a Comment

    Related Posts Plugin for WordPress, Blogger...