Java
  Home arrow Java arrow Page 2 - Working with JFC/Swing Controls using NetB...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Working with JFC/Swing Controls using NetBeans IDE
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2006-05-10

    Table of Contents:
  • Working with JFC/Swing Controls using NetBeans IDE
  • Working with text boxes, buttons, labels: understanding the code
  • Working with text boxes, buttons, labels: understanding the code continued
  • How about the JButton and its events?
  • Introducing error handling or exception handling in Java using NetBeans IDE
  • Introducing error handling or exception handling in Java using NetBeans IDE: explanation

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with JFC/Swing Controls using NetBeans IDE - Working with text boxes, buttons, labels: understanding the code


    (Page 2 of 6 )

    Let us go through the code created behind the controls.  I shall explain step by step.  Let us first consider the following:

        private javax.swing.JButton btnSum;
        private javax.swing.JLabel lblEnterFirst;
        private javax.swing.JLabel lblEnterSecond;
        private javax.swing.JLabel lblResult;
        private javax.swing.JTextField txtFirst;
        private javax.swing.JTextField txtSecond;

    Every control we dropped from the toolbox onto the form (or JFrame) would be coded as above.  In fact, every control we placed on the form would be treated as an object of the respective class.  In the above case, they are simply references to non existing objects.  The next code fragment would create the real objects and assign those objects to above references.  The name of the object/reference (in this case) would be the same, as we rename it during the design.

    Further proceeding we have the following:

      private void initComponents() {

    The line above contains the name (initComponents) of the method which is executed from within the constructor (please refer to the code fragment in the previous section).  The constructor is a special type of method, which has the same name as the class name and is executed automatically by itself (when the instance of that class has been created).

    Further proceeding we have the following:

    txtFirst = new javax.swing.JTextField();
         btnSum = new javax.swing.JButton();
         lblEnterFirst = new javax.swing.JLabel();
         lblEnterSecond = new javax.swing.JLabel();
         txtSecond = new javax.swing.JTextField();
         lblResult = new javax.swing.JLabel();

    All the above statements simply create objects of the controls we placed on the form. Those objects will be assigned to the references previously created.

      getContentPane().setLayout(null);

    The above statement assigns "no layout" to our frame (or to the content pane).  Every JFrame would be generally equipped with a special panel called "contentPane."  We will generally add controls to this "contentpane".  Which means, we need to specify the top, left, width, and height of every control ourselves (and nothing would be automated).

    More Java Articles
    More By Jagadish Chaterjee


       · Hello guys. Another article added on NetBeans IDE. enjoy :)
     

    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...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT