Create simple application of Java AWT in which show an awt component button by setting its placement and window frame size..
CODE:
import java.awt.Button;
import java.awt.Frame;
public class AWTButtonExample {
public static void main(String[] args) {
// Create a frame
Frame frame = new Frame("AWT Button Example");
// Create a button
Button button = new Button("Click Me");
// Set the size and position of the button
button.setBounds(100, 100, 80, 30);
// Add the button to the frame
frame.add(button);
// Set the frame size
frame.setSize(300, 200);
// Set frame layout to null (absolute positioning)
frame.setLayout(null);
// Make the frame visible
frame.setVisible(true);
}
}
Algorithm:
Import the required AWT classes (Frame and Button).
Define a class AWTButtonExample.
Inside the main method of the AWTButtonExample class:
a. Create an instance of Frame with the title "AWT Button Example".
b. Create an instance of Button with the label "Click Me".
c. Set the size and position of the button using the setBounds() method.
d. Add the button to the frame using the add() method.
e. Set the size of the frame using the setSize() method.
f. Set the layout of the frame to null (absolute positioning) using the setLayout(null) method.
g. Make the frame visible using the setVisible(true) method.
End of the program.