Working with JFC/Swing Controls using NetBeans IDE
This article focuses on programming with the text boxes, buttons and labels of JFC in Java using the NetBeans IDE. It also introduces you to exception handling in Java.
Working with JFC/Swing Controls using NetBeans IDE - Working with text boxes, buttons, labels: understanding the code continued (Page 3 of 6 )
This is the continuation of the previous section. Further proceeding we have the following:
setDefaultCloseOperation (javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Sample for adding two numbers");
You can observe that whatever properties you set during the design will be automatically converted to appropriate Java code. Now we shall see how all the controls are being added to the frame. Let us consider the following code fragment:
Our first text box is "txtFirst," and it needs to be added to the "contentpane." The fist line in the above code fragment accomplishes this. The second line simply specifies the top, left, width and height properties of the text box. Now, let us see how the other controls are added:
You could observe that adding labels is very similar to adding text boxes except that we are specifying some caption/text for a few labels. The last label (lblResult) was provided with a special type of border (a line border), just to make it different from the other labels.