当前位置:首页 > 开发 > 编程语言 > Java > 正文

Java中如何写代码实现无标题无边框的窗体能够用鼠标拖动改变窗口大小

发表于: 2014-01-23   作者:不懂事的小屁孩   来源:转载   浏览:
摘要: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DragFrame extends JFrame { private boolean startDrag = false; private Point p = null; public static void mai
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DragFrame extends JFrame {
	private boolean startDrag = false;
	private Point p = null;

	public static void main(String[] args) {
		DragFrame df = new DragFrame();
		df.setUndecorated(true);
		df.setSize(400, 400);
		df.setVisible(true);
	}

	public DragFrame() {
		addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				startDrag = true;
				p = e.getPoint();
			}

			public void mouseReleased(MouseEvent e) {
				startDrag = false;
			}
		});
		addMouseMotionListener(new MouseMotionAdapter() {
			public void mouseDragged(MouseEvent e) {
				Point p1 = e.getPoint();
				Point p2 = getLocation(null);
				p2.x += p1.x - p.x;
				p2.y += p1.y - p.y;
				setLocation(p2);
			}
		});
	}
}

Java中如何写代码实现无标题无边框的窗体能够用鼠标拖动改变窗口大小

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号