SunQuest
 
       Java
  Home arrow Java arrow Page 9 - 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
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Java's Basic User Interface Components - Setting a Password Character


    (Page 9 of 10 )

    The text Field allows you to specify an echo character that helps you accept a password without displaying what the user has keyed in. For example, say you have specified “*” as the echo character, and the user type in five character, “*****” is displayed in the text filed instead of the text the user has keyed in. To do this, first create the text field itself; then use the setEchoCharacter() method to set the character that is echoed on the screen. Here is an example:

    TextField tf = new TextField(30);tf.setEchoCharacter('*');

    The Applet in Example7 below creates several text fields. Labels are used to identify the fields. One of the fields uses an obscuring character to hide text being input. This applet uses the default layout manager, the only thing causing the six components to appear in three different lines is the width of the window.

    /*
    <Applet code= “TextfieldTest.class”
    Width = 400
    Height = 150>
    </Applet>
    */

    Import java.awt.*;
    Public class TextfieldTest extends java.applet.Applet
    {
    Label uLabel = new label (“User Name:”);
    TextField uText = new TextField (25);
    Label eLabel = new label (“Email ID:”);
    TextField eText = new TextField (25);
    Label pLabel = new label (“Admin Password:”);
    TextField pText = new TextField(25);

    Public void init(){
    add(uLabel);
    add(uText);
    add(eLabel);
    add(eText);
    add(pLabel);
    pText.setEchoCharacter(‘*’);
    add(pText);
    }
    }


    After creating the controls, we initialize them using the “new” keyword. Use the add() method to add controls to the container, in this case the applet. The other methods for TextField are:

    Method Action
    String getText() Extracts the text from the text field (as a string).
    Void setText(String str)Sets the text of the text field to the text specified in the str.
    Int getColumns()Returns the width of this text field.
    select(int, int) Selects the text between the two integer positions (positions start from 0)
    selectAll() Selects all the text in the field
    Boolean isEditable ()Returns true or false based on whether the text is editable
    Char getEchoChar()Returns the character used for masking input
    Boolean echoCharIsSet(char c) Returns true or false based on whether the field has a masking character

    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 6 hosted by Hostway