Java AWT Label
The object of the Label class is a component for placing text in a container. It is used to display a single line of read only text. The text can be changed by a programmer but a user cannot edit it directly.
It is called a passive control as it does not create any event when it is accessed. To create a label, we need to create the object of Label class.
AWT Label Class Declaration
AWT Label Fields
The java.awt.Component class has following fields:
Label class Constructors
Label Class Methods
The above methods are inherited by the following classes:
Java AWT Label Example
In the following example, we are creating two labels l1 and l2 using the Label(String text) constructor and adding them into the frame.
Java AWT Label Example with ActionListener
In the following example, we are creating the objects of TextField, Label and Button classes and adding them to the Frame. Using the actionPerformed() method an event is generated over the button. When we add the website in the text field and click on the button, we get the IP address of website.
Next TopicJava AWT TextField