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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
JAVA

Java's Basic User Interface Components
By: Gayathri Gokul
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    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:
      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
     
    IBM developerWorks
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    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

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway