Java
  Home arrow Java arrow 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  
Moblin 
JMSL Numerical Library 
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


    (Page 1 of 6 )

    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.
    A downloadable file for this article is available here.

    I already introduced the NetBeans IDE in my previous article "Developing Java Applications Using Netbeans."  We also managed to develop a "Hello World" application within the same article.  If you are new to NetBeans IDE, I strongly suggest you go through that article first, before proceeding with this one.

    The entire code for this article is freely available in the form of a zip file.  That downloadable solution is developed using NetBeans 4.1 IDE.  I didn't really test it in any other version.

    Working with text boxes, buttons, labels: Design

    In this section, we shall develop a small application with two text boxes, three labels and a button.  When the button is clicked, it should automatically add the two numbers available in two text boxes and show the result in a label ('lblResult').  Currently, I named the project "SampleJavaApplication1" and the form (or JFrame) "Sample01."

    When the form (or JFrame) is created with "Sample01," the code behind it (only the constructor) would look something like the following:

    public class Sample01 extends javax.swing.JFrame {

        /** Creates new form Sample01 */
       
    public Sample01() {
            initComponents();
        }

    Make changes to the above code fragment in such a way that it looks similar to the following:

      public class Sample01 extends javax.swing.JFrame {

        /** Creates new form Sample01 */
        public Sample01() {
            initComponents();
            this.setSize(300,200);
        }

    In the above code, I explicitly defined the initial size of the frame.  Before dropping all controls onto the form, set the layout to "null layout" (fig1), to ease our development for this article.  Later in my upcoming articles, I shall introduce you to the other powerful and more efficient layouts.  When you complete your form design, it should look something like the following (fig1).

    To keep the written code understandable, I named those controls as follows:

      txtFirst
      txtSecond
      lblEnterFirst
      lblEnterSecond
      lblResult
      btnSum

    I also gave a value to the Frame property "title" (using the property window), namely "Sample for adding two numbers."

    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 6 hosted by Hostway
    Stay green...Green IT