Creating an AWT Button the easy way :
new AWTButton() : Create the object for the class AWTButton
import java.awt.*;AWTButton() : Code for creation of an AWT Button is written here.
class AWTButton extends Frame
{
Button b1,b2;
public AWTButton()
{
// Set frame properties
setTitle("AWT Frame"); // Set the title
setSize(400,400); // Set size to the frame
setLayout(new FlowLayout()); // Set the layout
setVisible(true); // Make the frame visible
setLocationRelativeTo(null); // Center the frame
// Create buttons
b1=new Button(); // Create a button with default constructor
b1.setLabel("I am button 1"); // Set the text for button
b2=new Button("Button 2"); // Create a button with sample text
b2.setBackground(Color.lightGray); // Set the background to the button
add(b1);
add(b2);
}
public static void main(String args[])
{
new AWTButton();
}
}
new AWTButton() : Create the object for the class AWTButton