Java JFrame中从里到外由frame-layeredPane-contentPane-menuBar(optional)-glassPane构成。layered pane用处很大就不必说了。现在是其中glass pane的应用。
package com.han;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputListener;
/**
* It contains a check box that lets you set whether the glass pane is "visible"
* — whether it can get events and paint itself onscreen. When the glass pane is
* visible, it blocks all input events from reaching the components in the
* content pane. It also paints a red dot in the place where it last detected a
* mouse-pressed event.