Sunday, October 9, 2011

Create AWT Button Example

/*
Create AWT Button Example 
This java example shows how to create a Button using AWT Button class.
*/

import java.applet.Applet;
import java.awt.Button;


/*
<applet code="CreateAWTButtonExample" width=200 height=200>
</applet>
*/

public class CreateAWTButtonExample extends Applet{

public void init(){

/*
* To create a button use
* Button() constructor.
*/

Button button1 = new Button();

/*
* Set button caption or label using
* void setLabel(String text)
* method of AWT Button class.
*/

button1.setLabel("My Button 1");

/*
* To create button with the caption use
* Button(String text) constructor of
* AWT Button class.
*/

Button button2 = new Button("My Button 2");

//add buttons using add method
add(button1);
add(button2);
}

}


Output:







No comments:

Post a Comment