Apr 18, 2012


The simplest AWT component is label. Labels do not respond to the user inputs, and they do not send any other events.
 The following constructors are used to create a label.

Label(String caption)
Label(String caption, alignment)

The first constructor creates a empty label. The second one creates a specified text in the label. The default alignment to the label is left. The third constructor is used for creating a label with your alignment. The alignment values are:


There are two methods supports the reading and setting text for the label.

getText()    - It returns the text from the Label
setText()    - It set the text for the Label 


import java.applet.*;
import java.awt.*;
public class LabelDemo extends Applet
public void init()
             setLayout(new GridLayout(2,1));
             Label l1=new Label("Java Programming");
             Label l2=new Label("by surendranath Reddy",Label.CENTER);

<applet code="LabelDemo.class" width=200 height=75>

How to Execute this Example??

d:\>  javac LabelDemo.java
d:\>  appletviewer LabelDemo.java



Post a Comment