码迷,mamicode.com
首页 > 其他好文 > 详细

今天来个爪哇去边框的小代码

时间:2017-01-03 15:34:37      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:mouse   ora   event   ane   drag   point   int   代码   oca   

//先去除边框
setUndecorated(true);
//加入标签作为关闭按钮
		JLabel SubCloseLabel = new JLabel("");
//按钮的位置
		SubCloseLabel.setBounds(860, 0, 40, 30);
//单击监听
		SubCloseLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JLabel CloseLabel=(JLabel)e.getSource();
//获取顶层窗体
				SubWindow MySubWindowBuider=(SubWindow)CloseLabel.getTopLevelAncestor();
				MySubWindowBuider.dispose();
			}
		});
		SubPanel.setLayout(null);
//加入标签作为最小化按钮
		JLabel SubMinimizeLabel = new JLabel("");
		SubMinimizeLabel.setBounds(822, 0, 40, 30);
		SubMinimizeLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JLabel MinimizeLabel=(JLabel)e.getSource();
				SubWindow MySubWindowBuider=(SubWindow)MinimizeLabel.getTopLevelAncestor();
				MySubWindowBuider.setExtendedState(JFrame.ICONIFIED);
			}
		});
//拖动的标签
		JLabel SubDragLabel = new JLabel("");
		SubDragLabel.setBounds(0, 0, 822, 30);
		SubDragLabel.addMouseMotionListener(new MouseMotionAdapter() {
			@Override
			public void mouseDragged(MouseEvent e) {
				JLabel DragLabel=(JLabel)e.getSource();
				SubWindow MyWindowBuider=(SubWindow)DragLabel.getTopLevelAncestor();
				Point p = MyWindowBuider.getLocation();
				MyWindowBuider.setLocation(p.x+(e.getX()-suborigin.x),p.y+(e.getY()-suborigin.y)); 
			}
		});
		SubDragLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				suborigin.x=e.getX();
				suborigin.y=e.getY();
			}
		});
		SubPanel.add(SubDragLabel);                                                                                                                           

  

今天来个爪哇去边框的小代码

标签:mouse   ora   event   ane   drag   point   int   代码   oca   

原文地址:http://www.cnblogs.com/mubu/p/6244679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!