//AutoHiddenFrame /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package autohiddenframe; import java.awt.BorderLayout; import java.awt.Insets; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; /** * * @author Administrator */ public class AutoHiddenFrame extends JFrame { /** * @param args the command line arguments */ private static final long serialVersionUID = 1L; public static void main(String args[]) { new AutoHiddenFrame(); } public static final int NORMAL = 0; //窗体的普通状态 public static final int CANHIDD = 1; //窗体位于屏幕边缘,可以隐藏的状态 public static final int HIDDEN = 2; //窗体处于隐藏状态 private int state = NORMAL; //窗体的状态,让它初始化为普通状态 private Point hiddenPoint; //隐藏窗体时,窗体的位置 private Point visiblePoint; //窗体处于显示状态时的位置 private JLabel infoLabel; //用于显示信息的JLabel; public AutoHiddenFrame() { JPanel p = new JPanel(new BorderLayout()) { private static final long serialVersionUID = 1L; public Insets getInsets() { return new Insets(3,3,3,3); } }; setContentPane(p); //替换掉原来的ContentPane,换上一个带有Insets的,至于为什么去看WindowMouseListener类 infoLabel = new JLabel(); add(infoLabel,BorderLayout.SOUTH); setSize(300,200); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); new WindowLocationListener(this); new WindowMouseListener(this); WindowLocationListener.checkAutoHiddenState(this);//刚出来就检查一下窗体的位置 } /** * @param newState 新的状态 * 一定要是此类中定义的3中状态之一 */ public void setStates(int newState) { if(newState == NORMAL || newState == CANHIDD || newState == HIDDEN) { state = newState; } } /* * 返回状态,注意此方法和setStates方法区别与JFrame中的setState()和getState()方法 */ public int getStates() { return state; } /* * 设置要显示时窗体的坐标 */ public void setVisiblePoint(Point point) { visiblePoint