R4R
Right Place For Right Person TM
 

R4R JAVAAWT ExamplesCreate Label in java in java

previous

Home

Next

Create Label in java in java
In this example we are going to creat Label.To control the button we are using three type of package. One is java.awt.* second is  java.applet.* and third is java.awt.event.*; .The java.awt.* is used for GUI interface. .

Label defines three constructors:
Label(): Is use to create an empty button.
Label(String str)
: Is use to create a Label that contains String str as label.
Label(string str, int how):
It contain the string str using alignment specified by how.
In our example we creates  four label One, two, three, four. you can change the text using setText() method. you can obtain the current label by calling getText() method.

The method are:
void setText(String str);
String getText();



//creat Label
import java.awt.*;
import java.applet.*;
/*
<applet code="LabelDemo" width=300 height=200>
</applet>
*/
public class LabelDemo extends Applet{
public void init(){
Label one = new Label("One");
Label two = new Label("Two");
Label three = new Label("Three");
Label four = new Label("Four");
add(one);
add(two);
add(three);
add(four);
}
}

Download Source Code

Output Of Example

previous

Home

Next

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R