Java
  Home arrow Java arrow Page 3 - Java's Basic User Interface Components
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
Google.com  
JAVA

Java's Basic User Interface Components
By: Gayathri Gokul
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 15
    2003-10-20


    Table of Contents:
  • Java's Basic User Interface Components
  • Adding a Control to a Container
  • The Button Class
  • The Label Class
  • The Checkbox Class
  • The CheckboxGroup Class
  • The Choice List Class
  • The TextField and TextArea Class
  • Setting a Password Character
  • TextArea

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Java's Basic User Interface Components - The Button Class
    ( Page 3 of 10 )

    We will start with the simplest of UI components: the button. Buttons are used to trigger events in a GUI environment (we have discussed Event Handling in detail in the previous tutorials). They are easy to manage and, most importantly, they are easy to use. The Button class is used to create buttons. When you add components to the container, you don’t specify a set of coordinates that indicates where the components are to be placed. The arrangement of components is handled by a layout manager in effect for the container. The default layout for a container is flow layout. Now let us write a simple code to test our button class.
    To create a button use, one of the following constructors:
    • Button() creates a button with no text label.
    • Button(String) creates a button with the given string as label.


    Example 1

    /*
    <Applet code= “ButtonTest.class”
    Width = 500
    Height = 100>
    </applet>
    */

    Import java.awt.*;
    Public class ButtonTest extends java.applet.Applet
    {
    Button b1 = new Button (“Play”);
    Button b2 = new Button (“Stop”);

    Public void init(){
    add(b1);
    add(b2);
    }
    }


    The following Java application illustrates addition of button controls to a panel.

    Example 2

    Import java.awt.*;

    Public class ButttonTest2 extends Frame
    {
    Public static void main (String arg[])
    {
    Frame frm;
    Panel panel,
    Button b1, b2,
    frm= new Frame(“Using Frame As Container For-Button Test”);
    frm.setSize(300,400);
    frm.setBackground (Color.green);
    frm.setVisible(true)

    panel = new Panel();
    b1 = new Button(“Accept”);
    b2 = new Button(“Cancel”);

    frm.add(panel);
    panel.add(b1);
    panel.add(b2);
    }
    }


    We can use the setLabel( ) method to change the label of the button and the getLabel( ) method to retrieve the caption.

     
     
    >>> More Java Articles          >>> More By Gayathri Gokul
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek