|
The controls are basically the components which are required by any programmers at the time of interacting with that particular application. Now AWT controls are basically the components which a programmer will be using at the time of interacting with any GUI object like the panel, frame or a window.
These controls play an important role in AWT as they are used very effectively by the programmers, For example a very simple and frequently used control is the push button or the submit button. All these controls are subclasses of Component.
We also have the flexibility of adding and removing any particular control in AWT. This is done by:
Add ( ) method is used to add a control in a window.
Remove ( ) is used to remove or erase any control from a window.
void remove(Component obj)
We have few controls available in AWT which we will study in brief now one by one
1. Labels
2. Push buttons
3. Check boxes
4. Choice lists
5. Lists
6. Scroll bars
7. Text editing
1 .Labels: Labels have few constructors which are mentioned below:
Label ( ): This constructor will create a blank Label.
2. Label (String str) This constructor is used to create a label with the specified label which is passes as parameter.
Methods associated with the Labels are:
1. getText (): This method helps to obtain the current label.
String getText( )
2. setText ( ): This method is used to set or change the text in a label.
void setText(String str)
3. setAlignment ( ): This method is used to set the alignment.
void setAlignment(int how)
2. Buttons
2. Push Button: Push buttons are very commonly used with the programmers.
It consists of a label which acts as a name of that button and has an event which gets activated once it is clicked .Push button are the objects of Buttons class.
Button defines these two constructors:
1. Button ( ): This constructor creates a default empty button.
2. Button (String str): This creates a button with name specified as parameter.
Few methods associated with buttons are:
1. getLabel ( ): This method is used to find out the name of a particular button. Its syntax is :
String getLabel( )
2. setLabel ( ): This method will set or change the name of the button. Its syntax is:
void setLabel(String str)
3. Check Boxes
A check box is a small box which enables the user to either select it clicking on it to check or uncheck it. It can be done by once clicking on that box and next deactivating it by again clicking on it. They can be implemented to work individually or in group too depending upon the user’s requirement. They are the objects of Check Box class.
Few constructors of Check Boxes are described below:
1. Checkbox ( ): It is used to create a check box whose label is initially blank and its state is unchecked.
2. Checkbox (String str): This creates a check box whose label is specified by str and the state of check box too is unchecked.
3. Checkbox (String str, boolean on): This is used to set the initial state of the check box and In this If on is true, the check box is checked else not.
Few methods associated with the Check Boxes are:
1. getState( ): This is used to get the current state of the check box.
boolean getState( )
2. setState ( ): This method is used to set the state of the check box.
void setState(boolean on)
String getLabel( )
void setLabel(String str)
4. Choice Controls
The Choice class is implemented when a user wants to select an element from a pop up list of items or elements. It works very similarly to the menu. The moment user clicks on it the entire list of elements gets displayed in front of it else only one item is displayed.
Few methods related to this are:
1. add( ): this is used to add a selection to the list.
void add(String name)
2. getSelectedItem () : This will return the value as the item which is currently selected.
String getSelectedItem( )
3. getItemCount( ) : This is used to obtain the number of items in the list.
int getItemCount( )
5. Lists
List class enables the user to create a list of elements from which he can select a single element or multiple elements with the help of control key .It consists of few constructors which are as under:
1. List ( ): This constructor creates a default list which will let the user select a single item or element at a time.
2. List(int numRows): This is used to create a list with the specified number of row in the list.
3. List(int numRows, boolean multipleSelect) : This is used to create a list with specified number of rows and allowing the option of multiple selection at a time if the Boolean value passed is true.
Few methods associated with List are :
1. add( ) is used to add selection to a particular list. It has the following two forms:
void add(String name)
void add(String name, int index)
2. getSelectedItem( ) : This is used to get a string which contains the name of the particular item.
String getSelectedItem( )
3. getItemCount( ): This method is used to obtain the number of items in the list. Its syntax is:
int getItemCount( )
6. Scroll Bars
A scroll bar consists of various individual parts and is sued to select a continuous value between the minimum and maximum. It helps the user to move anywhere on the screen with the help of the arrows present on all four corners of the frame or screen or window. They are encapsulated by the Scrollbar class.
Scrollbar has few constructors which are as under:
1. Scrollbar ( ): This is used to create a vertical Scroll bar.
2. Scrollbar(int style): It creates a scroll bar with specified orientation.
Few methods associated with Scroll Bars are:
1. getValue( ) is used to obtain the current value of the scroll bar. Its syntax is
int getValue( )
2. setValue( ) is used to set the current value
void setValue(int newValue)
3. getMinimum( ) is sued to retrieve the minimum value in a scroll bar. Its syntax is
int getMinimum( )
4. getMaximum( ) is used to retrieve the maximum values . Iys Syntax is
int getMaximum ( )
7. TextField: This is used to write a single line of text. It enables to Performa all the cut, copy and paste operation easily on the text. Since it is a subclass of TextComponent it lets to perform methods like getText () and setText ( ) on it.
Few Constructors of TextField are:
1. TextField( ): it creates a default Text filed.
2.TextField(int numChars): This is used to create a text field with specified length limit.
3. TextField(String str): It is used to create a text field with the specified string.
4. TextField(String str, int numChars): it is used to create a text field with the specified string and width mentioned as parameters.
Few methods related to TextField are:
1. getText ( ): This method helps to retrieve the string which is currently in the text. Its syntax is:
string getText( )
2. setText( ): This method is used to set a new striung in the text.
void setText(String str)
3. getselectedText ( ) is used to get the currently selected text in a text field. Its syntax is
String getSelectedText( )
8. TextArea
Textarea is used when we need to write multiple lines of text and thus it is called multiline editor. Since TextArea is a subclass of TextComponent. It very successfully performs the getText( ), setText( ),
getSelectedText( ), select( ), isEditable( ), and setEditable( ) methods.
Few Constructors for TextArea are:
1.TextArea( )
2.TextArea(int numLines, int numChars)
3.TextArea(String str)
4. TextArea(String str, int numLines, int numChars)
5. TextArea(String str, int numLines, int numChars, int sBars)
Few methods of TextArea are:
1. void append(String str): This method adds the string to the end of the current text.
2. void insert(String str, int index): This method is used to insert the text at the specified position in between the text.
3. void replaceRange(String str, int startIndex, int endIndex): This method is used to replce a string with another specified string at the specified place.
|