**********************************************************************
COMPLETE SOURCE CODE FOR : CloseJFrameUsingMouseHover.java
**********************************************************************
import javax.swing.JFrame;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class CloseJFrameUsingMouseHover
{
public static void main(String[]args)
{
//Create mouse listener that will listen when someone hover on JFrame
MouseListener ml=new MouseAdapter()
{
public void mouseEntered(MouseEvent event)
{
//Put JFrame close code here
System.exit(0);
}
};
//Create JFrame with title ( HOVER ON THE BOX BELOW !!!!!!!!! )
JFrame frame=new JFrame("HOVER ON THE BOX BELOW !!!!!!!!!");
//Add mouse listener to JFrame
frame.addMouseListener(ml);
//Set default close operation to JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set JFrame size to :
//Width : 400 pixels
//Height : 400 pixels
frame.setSize(400,400);
//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}
**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************