今天来个爪哇去边框的小代码
Posted 木卜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了今天来个爪哇去边框的小代码相关的知识,希望对你有一定的参考价值。
//先去除边框 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);
以上是关于今天来个爪哇去边框的小代码的主要内容,如果未能解决你的问题,请参考以下文章
Android课程---Android Studio使用小技巧:提取方法代码片段