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."
Next: The heart of the application >>
More Java Articles
More By Jagadish Chaterjee