Creating an AWT Button : Quick steps

Creating an AWT Button the easy way :
import java.awt.*;
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
    public static void main(String args[])
    new AWTButton();
AWTButton() : Code for creation of an AWT Button is written here.
new AWTButton() : Create the object for the class AWTButton

Posted by at on

Tags: Abstract Window Toolkit,