Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Java AWT Components

                         

Introduction

In this section you will learn about the different components available in the Java AWT package for developing user interface for your program.

Following some components of Java AWT are explained : 

  1. Labels : This is the simplest component of Java Abstract Window Toolkit. This component is generally used to show the text or string in your application and label never perform any type of action. Syntax for defining the label only and with justification : 

    Label label_name = new Label ("This is the label text.");
    Above code simply represents the text for the label.
    Label label_name = new Label ("This is the label text.", Label.CENTER);
    Justification of label can be left, right or centered. Above declaration used the center justification of the label using the Label.CENTER.  
      
  2. Buttons : This is the component of Java Abstract Window Toolkit and is used to trigger actions and other events required for your application. The syntax of defining the button is as follows : 

    Button button_name = new Button ("This is the label of the button.");
    You can change the Button's label or get the label's text by using the Button.setLabel(String) and Button.getLabel() method. Buttons are added to the it's container using the add (button_name) method.
      
  3. Check Boxes : This component of Java AWT allows you to create check boxes in your applications. The syntax of the definition of Checkbox is as follows : 

    CheckBox checkbox_name = new Checkbox ("Optional check box 1", false);
    Above code constructs the unchecked Checkbox by passing the boolean valued argument false with the Checkbox label through the Checkbox() constructor. Defined Checkbox is added to it's container using add (checkbox_name) method. You can change and get the checkbox's label using the setLabel (String) and getLabel() method. You can also set and get the state of the checkbox using the setState(boolean) and getState() method provided by the Checkbox class.
      
  4. Radio Button : This is the special case of the Checkbox component of Java AWT package. This is used as a group of checkboxes which group name is same. Only one Checkbox from a Checkbox Group can be selected at a time. Syntax for creating radio buttons is as follows :

    CheckboxGroup chkgp = new CheckboxGroup();
    add (new Checkbox ("One", chkgp, false);
    add (new Checkbox ("Two", chkgp, false);
    add (new Checkbox ("Three",chkgp, false);

    In the above code we are making three check boxes with the label "One", "Two" and  "Three". If you mention more than one true valued for checkboxes then your program takes the last true and show the last check box as checked.
      
  5. Text Area: This is the text container component of Java AWT package. The Text Area contains plain text. TextArea can be declared as follows:

    TextArea txtArea_name = new TextArea();
    You can make the Text Area editable or not using the setEditable (boolean) method. If you pass the boolean valued argument false then the text area will be non-editable otherwise it will be editable. The text area is by default in editable mode. Text are set in the text area using the setText(string) method of the TextArea class.
       
  6. Text Field: This is also the text container component of Java AWT package. This component contains single line and limited text information. This is declared as follows :

    TextField txtfield = new TextField(20);
    You can fix the number of columns in the text field by specifying the number in the constructor. In the above code we have fixed the number of columns to 20.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

Its excellent.I will give commets later.

Posted by Bibhuti on Friday, 10.12.07 @ 16:11pm | #33439

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.