Java simple theory notes for AWT controls part1
AWT controls (java AWT)
Controls are components that allow the user to interact with an application. `A component is a visual object containing text or graphics.It can respond to keyboard or mouse input.The java AWT supports several types of control.These are listed below:
- Labels
- Buttons
- Lists
- Radio Buttons
- Scroll Bars
- Text Field
- Choice Lists
- Text Area
- Check Boxes
Labels
How to create a label?
syntax for creating labels:
Label label1=new Label();
Label label2=new Label(String);
Label label3=new Label(String,int);
Here label1,label2,label3 is the object name, the programmer can give the desired name as the object name.
Given above are three types of constructor for the label
The first one creates a blank label.
The second one is to create a label with a specified string.
The third one specifies how text is aligned within the label.So, the second argument int will take the values Label.RIGHT, Label.CENTER and Label.LEFT, which are constant defined in Label class.
In the Label class, there are two methods are availables, getText() and setText().
Remember the java naming convention
Buttons
Push buttons are widely used in java AWT. These contain a label that specifies the name of the button. Whenever a push button is clicked, it generates an event and executes the code of the specified listener.
How to create a Button?
syntax for creating Button:
Button button1=new Button();
Button button2=new Button(String);
Here button1,button2 is the object name, the programmer can give the desired name as the object name.
Here also the label can be set using the setLabel(String)method and it can be got using the getLabel() method.
Comments
Post a Comment