Java
  Home arrow Java arrow Page 3 - 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 
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 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:

      getContentPane().add(txtFirst);
      txtFirst.setBounds(130, 20, 130, 20);

    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:

      getContentPane().add(txtSecond);
      txtSecond.setBounds(130, 50, 130, 20);

      lblEnterFirst.setText("Enter First No:");
     
    getContentPane().add(lblEnterFirst);
     
    lblEnterFirst.setBounds(20, 20, 90, 14);

      lblEnterSecond.setText("Enter Second No:");
      getContentPane().add(lblEnterSecond);
      lblEnterSecond.setBounds(20, 50, 100, 14);

      lblResult.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
      getContentPane().add(lblResult);
      lblResult.setBounds(130, 110, 130, 14);

    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.

    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-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT