Home arrow Java arrow Page 2 - Finding and Traversing Rows using NetBeans IDE
JAVA

Finding and Traversing Rows using NetBeans IDE


This series introduces you to a step-by-step process to develop Java (or JFC) based applications with Microsoft SQL Server as the database, using NetBeans IDE. In this article, I shall introduce you to finding and traversing rows using Java.

Author Info:
By: Jagadish Chaterjee
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
June 21, 2006
TABLE OF CONTENTS:
  1. · Finding and Traversing Rows using NetBeans IDE
  2. · The code generated
  3. · The heart of the application
  4. · Explaining the code

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Finding and Traversing Rows using NetBeans IDE - The code generated
(Page 2 of 4 )

In this section, I shall give you some overview of the code generated behind the application.  Let me start part by part.

private javax.swing.JButton btnSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel lblMsg;
    private javax.swing.JTextField txtDeptno;
    private javax.swing.JTextField txtEmpno;
    private javax.swing.JTextField txtEname;
    private javax.swing.JTextField txtSal;

Each and every control we drop at design time will be coded something like the snippet above. The respective class will be automatically chosen based on the control you drop from the palette.  Proceeding further, we have the following:

private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        txtEmpno = new javax.swing.JTextField();
        btnSearch = new javax.swing.JButton();
        txtEname = new javax.swing.JTextField();
        txtSal = new javax.swing.JTextField();
        txtDeptno = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblMsg = new javax.swing.JLabel();

Every control gets instantiated within "initComponents," which gets executed from the contructor (as shown in previous section).

getContentPane().setLayout(null);
jLabel1.setText("Empno:");
getContentPane().add(jLabel1);
jLabel1.setBounds(20, 10, 80, 14);
getContentPane().add(txtEmpno);
txtEmpno.setBounds(90, 10, 90, 20);
.
.
.

Currently, for this series, I set "Layout" to null so that I can define my own bounds for every control.  From the above code, you can observe that every control is being provided with certain property values and finally being added to the content panel based on the bounds specified.

The button declaration would be a bit different because it has some "event" to be published. The following is the relative code for the same:

btnSearch.setText("Search");
        btnSearch.addActionListener(new
java.awt.event.ActionListener() {
            public void actionPerformed
(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });
        getContentPane().add(btnSearch);
        btnSearch.setBounds(190, 10, 90, 23);

The above code would simply add a "listener" to the button; we need to write our "button event handling" code in "btnSearchActionPerformed."


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials