Java AWT LabelThe 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 DeclarationAWT Label FieldsThe java.awt.Component class has following fields:
Label class Constructors
Label Class MethodsSpecified
Method inheritedThe above methods are inherited by the following classes:
Java AWT Label ExampleIn the following example, we are creating two labels l1 and l2 using the Label(String text) constructor and adding them into the frame. LabelExample.java Output: Java AWT Label Example with ActionListenerIn 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. LabelExample2.java Output: Next TopicJava AWT TextField |