Java simple theory notes for AWT controls part4
Easy and tasty Christmas cake recipes
TextField Control
TextField control holds a single line of text that can be edited.Hence, this control is called editable control.
The TextField control is a Sub-Class of the TextComponent class.It can be created using the following constructors:
TextField test1=new TextField();
TextField test2=new TextField(int);
TextField test3=new TextField(String);
TextField test4=new TextField(String,int);
Here test1,test2,test3 and test4 are the object name, the programmer can give the desired name as the object name.
The first and third constructors create the default TextField. The Second and fourth creates a TextField of size specified by the number of characters.
The text field control has the methods getText() and setText(String) for getting and setting the values in the text field.
The text field can be made editable or non-editable by using the following methods:
SetEditable(boolean);
isEditable();
The isEditable() method returns the boolean value true if the text field is editable and the value false if the text field is non-editable.
Another important characteristic of the text field is that the echo character can be set, while entering Password-like values.
To set echo characters the following method is called.
void setEchoChacter(char)
The echo character can be obtained and it can be checked it the echo character has been set using the following methods:
getEchoCharacter();
boolean echoCharIsSet();
Since the text field also generates the ActionEvent, the ActionListener interface can be used to handle any type of action performed in the text field. The selected text within the text field can be obtained by using the TextField interface.
Remember Java's naming convention
importance of interface in java
Scrollbars:
Scroll bars are used to select some values from a range. A Scroll bar has a thumb, which is dragged to change the value. It can be formed with The following constructor:
Scrollbar( );
Scrollbar(int);
Scrollbar(int,int,int,int,int );
The Second constructor creates a scrollbar with specified orientation, that is, horizontal and vertical.
The third form specifies the initial value and maximal value along with the thumb size.
After initiating the scroll with the default constructor, the values can be set using the following method:
void setValues( int, int, int);
The method getValue( ) and SetValue( ) are used to get and set the value of the Scrollbar at a particular instant.
The unit increment and block increment can be set using the methods:
void setUnitIncrement( int)
void setBlockIncrement(int)
The minimum value and the maximum value of the Scrollbar can be obtained using getMinimum() and getMaximum( ) methods.
There are two types of the Scrollbars - Vertical and horizontal.
When creating Scrollbars, the constands Scrollbar.VERTICAL and Scrollbar.HORIZONTAL are used.
When a block in the Scrollbar is adjusted, an AdjustmentEvent is generated and hence the AdjustmentListener interface has to be used to handle the scrollbar.
Nice blog and informative content,
ReplyDeleteThanks for sharing with us,
Best JAVA Training in Hyderabad
Best JAVA Online Training in Hyderabad