AWT Label Class
Create AWT Label with simple Example..........
INTRODUCTION
Create AWT Label with simple Example..........
INTRODUCTION
Label component displays text just like a drawString(). The difference is Label gets the status of a component so that it can be added in position format using layout manager. Label displays text in one line only. User cannot edit the text of the label. It is meant only for the programmer to display some information. The label does not raise any events (the other only component that does not raise events is Panel).
FIELDS
Following are the fields for java.awt.Component class:
- static int CENTER
- static int LEFT
- static int RIGHT
public static final int LEFT = 0 label is aligned to left
public static final int CENTER = 1 label is aligned to center
public static final int RIGHT = 2 label is aligned to right
Following is the class signature
public class Label extends Component implements Accessible
CLASS CONSTRUCTORS
S.N. Constructor & Description
1 Label()
Constructs an empty label.
2 Label(String text)
Constructs a new label with the specified string of text, left justified.
3 Label(String text, int alignment)
Constructs a new label that presents the specified string of text with the
specified alignment.
Example:
import java.awt.*;
import java.applet.Applet;
public class MyLabel extends Applet
{
public void init()
{
add(new Label("label one"));
add(new Label("label two", Label.RIGHT));
}
}
Output:
No comments :
Post a Comment