Q.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. [15 M]
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame implements WindowListener
{
MyFrame()
{
// Set title
setTitle("TYBBACA");
// Set size
setSize(400, 300);
// Set background color
setBackground(Color.RED);
// Add window listener
addWindowListener(this);
// Make frame visible
setVisible(true);
}
// Close frame when close button clicked
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
// Unused methods (must be implemented)
public void windowOpened(WindowEvent we) {}
public void windowClosed(WindowEvent we) {}
public void windowIconified(WindowEvent we) {}
public void windowDeiconified(WindowEvent we) {}
public void windowActivated(WindowEvent we) {}
public void windowDeactivated(WindowEvent we) {}
public static void main(String args[])
{
new MyFrame();
}
}