去掉JFrame窗口边框之后的移动

class MoveListener extends MouseAdapter {
		int x0, y0, x1, y1;

		public void mousePressed(MouseEvent e) {
			x0 = e.getXOnScreen();
			y0 = e.getYOnScreen();
		}

		public void mouseDragged(MouseEvent e) {
			if (!isMax) {// 不是最大化的时候才可以移动
				x1 = e.getXOnScreen();
				y1 = e.getYOnScreen();

				if (x1 != x0 || y1 != y0) {
					Point p = ChatUI.this.getLocation();
					double px = p.getX();
					double py = p.getY();

					ChatUI.this.setLocation((int) (px + (x1 - x0)),
							(int) (py + (y1 - y0)));
					x0 = x1;
					y0 = y1;
				}
			}
		}
	}

 将这个监听器加到某个面板,点击这个面板就可以移动.

典型示例:QQ登陆窗口的移动.

你可能感兴趣的:(JFrame)