THE BUTTON COMPONENT CLASS
A button component class provided label feature and some respond when pressed it.button is more power full component of awt kit it control all event that related to other components .this component respond in different conditions like click,mouse move,mouse over,mouse release, etc.This component declared by following methods
Button b=new Button();
Button() -construct a button with no label
Button(String lable)-construct a button with specified label.
Methos
setLabe(string label)-It set the label of button to he specified string
getLabel()-Gets the Label from the button.
a simple java program that show Button component properties.
import java.awt.*;
public class frame
{
public static void main(String args[])
{
Button b1;//declare button component
Frame f=new Frame("new frame");//declare frame component with title new frame
f.setSize(300,150);//set size of frme
b1=new Button("click Me");//make a button component
f.add(b1);//add button component at frame
f.setLocation(200,200);//set position frame on computer screen
f.setVisible(true);//make visible frame
System.out.println("Press control+c keys for close programs");
}
}
The set Location(int x, int y)-This method define where show frame at screen x and y is a coordinate value;
The add() is used for adding component in a program.In this program creating only one Button component
so Button display at full screen.
0 comments:
Post a Comment