Saturday, 4 November 2023

Write a java program using AWT to create a Frame with title “TYBBACA”, background color RED. If user clicks on close button then frame should close.-core java slip20

 

Write a java program using AWT to create a Frame with title “TYBBACA”, background color RED. If user clicks on close button then frame should close.

import java.awt.*;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

 

public class RedFrame {

    public static void main(String[] args) {

        Frame frame = new Frame("TYBBACA");

       

        frame.setBackground(Color.RED);

 

        // Add a window listener to close the frame when the close button is clicked

        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {

                System.exit(0);

            }

        });

 

        frame.setSize(400, 400);

        frame.setVisible(true);

    }

}