16)Write a Java program which will create a frame if we try to close it, it should it’s color and it remains visible on the screen(Use swing).


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
class ColorDemo extends JFrame
{
JPanel p = new JPanel();
ColorDemo ()
{ setVisible(true);
setSize(400,400);
setTitle(“Swing Background”);
add(p);

p.setBackground(Color.BLACK);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
p.setBackground(Color.RED);
JOptionPane.showMessageDialog(null,”BackGraound Color is”+
p.getBackground(),”Color “,JOptionPane.INFORMATION_MESSAGE);
new ColorDemo ().show();
}
});
}

public static void main(String args[])
{
new ColorDemo ().show();
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s