Friday, December 18, 2009

My First Java Swing based Application

The purpose of this application, is to format book descriptions in a prescribed HTML template for listing in Ebay. To this, I will be designing the app using Java Swing components with help of Netbeans IDE.

Since this is my first project that I would like to seriously complete, I have decided to use the Celsius Converter project in the Java Tutorials as a reference example.

Project Creation
Created a New project(General Java Application) with the name BookDescription. Unchecked the 'create main class' option as suggested in the CelsiusConverter project. On clicking the finish button the project was created

Create New JFrame
After successful creation of the project, the project name BookDescription appears in the Project window towards the extreme left. Now right-click on the project name, then click on 'New' and select 'JFrame Form'. A new JFrame appears in the project window.



Entering a Title Name
Select JFrame in the inspector window. Now in the Properties window at extreme right, single-click on the empty box against the 'title' property and enter the title name as Book Description.





Placing the Components
Place the swing components, by dragging them one after the other from the pallete window at the top right corner, into the JFrame. The list of components required for this project are:
  • JTextField - 6
  • JLabel - 5
  • JRadioButton - 2
  • JButton - 1
  • JTextArea - 1
. Now, adjust the components in the required position and also resize them. If you see now, the components are named as JTextField1, JLabel1, JLabel2, JTextArea... etc which is not we want. Hence, rename appropriately with suitable names based on the project requirement. To rename, simply right-click twice on the components adn then rename. Care should be taken, while removing text from JTextField, as the component will get compressed when text is removed. If you do not want to display any text in JTextField, resize them accordingly.


Understanding the Components
  1. Title: The Title of the book
  2. Author: The Author(s) of the book
  3. ISBN-10: The 10 character International Standard Book Number.
  4. ISBN-13: The 13 digit International Standard Book Number.
  5. Pages: Number of pages
  6. Format: The bound of the book either paperback or hardcover
  7. Delivery Time: Number of days required for shipping the book - either 7-8 days or 14 days
  8. Description: Text-area for inputting publisher's description about the book and outputting HTML code also
  9. Generate: To generate HTML code for the formatted document

Renaming of Component Variable Names

Now that the form along with the components in it are ready, we can go ahead with coding the logic for the application. But before doing it, we need to change the Variable Names of each component, which will be effected in coding. This can be done from the inspector window. Initially, all the components have common names such as JTextField1, JTextField2, JLabel1... etc with there typename, in the square brackets on the right side. To change the variable name just right-click on each of them and then select Change Variable Name... as shown in the image.

No comments:

Post a Comment