Skip to main content

krushnaaa

 import java.awt.*;

import java.awt.event.*;

public class SimpleAWTExample {
    public static void main(String[] args) {
        // Create a Frame
        Frame frame = new Frame("Simple AWT Example");

        // Create a Button
        Button button = new Button("Click Me!");

        // Set layout for the Frame
        frame.setLayout(new FlowLayout());

        // Add the Button to the Frame
        frame.add(button);

        // Set size of the Frame
        frame.setSize(300, 200); // Width: 300 pixels, Height: 200 pixels

        // Make the Frame visible
        frame.setVisible(true);

        // Add a WindowListener to handle closing event
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}







Popular posts from this blog

Write a program to create a class Student2 along with two method getData (), printData () to get the value through argument and display the data in printData. Create the two objects s1, s2 to declare and access the values from class STtest.

 CODE: import java.util.Scanner; class Student2 {     private String name;     private int age;          // Method to set data     public void getData(String name, int age) {         this.name = name;         this.age = age;     }          // Method to print data     public void printData() {         System.out.println("Name: " + name);         System.out.println("Age: " + age);     } } public class STtest {     public static void main(String[] args) {         Scanner scanner = new Scanner(System.in);                  // Creating objects of Student2 class         Student2 s1 = new Student2();         Student2 s2 = new Student2();              ...