博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swing 设置无边框Frame
阅读量:5105 次
发布时间:2019-06-13

本文共 2938 字,大约阅读时间需要 9 分钟。

1 import java.awt.*; 2 import java.awt.event.*; 3 import javax.swing.*; 4  5 public class LogANA extends JFrame { 6  7     //背景图片bgImage 8     private ImageIcon bgImage = new ImageIcon("src/main/images/bg.jpg"); 9     //用于处理拖动事件,表示鼠标按下时的坐标,相对于JFrame10     int xOld = 0;11     int yOld = 0;12 13     private ImageIcon bt1mage = new ImageIcon("src/main/images/mini.png");14     private ImageIcon bt1mage_enable = new ImageIcon("src/main/images/mini_enable.png");15     private ImageIcon bt2mage = new ImageIcon("src/main/images/close.png");16     private ImageIcon bt2mage_enable = new ImageIcon("src/main/images/close_enable.png");17 18 19 20     public LogANA() {21 22         getContentPane().setLayout(new BorderLayout());23         this.setLocationRelativeTo(null);24         this.setSize(bgImage.getIconWidth(), bgImage.getIconHeight());25 26         //处理拖动事件---去掉默认边框后,不能拖动了,具体实现如下27         this.addMouseListener(new MouseAdapter() {28             @Override29             public void mousePressed(MouseEvent e) {30                 xOld = e.getX();//记录鼠标按下时的坐标31                 yOld = e.getY();32             }33         });34 35         this.addMouseMotionListener(new MouseMotionAdapter() {36             @Override37             public void mouseDragged(MouseEvent e) {38                 int xOnScreen = e.getXOnScreen();39                 int yOnScreen = e.getYOnScreen();40                 int xx = xOnScreen - xOld;41                 int yy = yOnScreen - yOld;42                 LogANA.this.setLocation(xx, yy);//设置拖拽后,窗口的位置43             }44         });45 46 47         JPanel mainPanel = new JPanel();48         mainPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));49         mainPanel.setSize(bgImage.getIconWidth(), 100);50         mainPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));51 52         //关闭按钮53         JButton miniBtn = new MyIconButton(bt1mage, bt1mage_enable, bt1mage, "");54         mainPanel.add(miniBtn);55 56         //关闭按钮57         JButton closeBtn = new MyIconButton(bt2mage, bt2mage_enable, bt2mage, "");58         mainPanel.add(closeBtn);59 60 61         getContentPane().add(mainPanel, BorderLayout.CENTER);62 63         closeBtn.addActionListener(new ActionListener() {64             @Override65             public void actionPerformed(ActionEvent e) {66                 System.exit(0);67             }68         });69 70         miniBtn.addActionListener(new ActionListener() {71             @Override72             public void actionPerformed(ActionEvent e) {73                 setExtendedState(JFrame.ICONIFIED);//最小化窗体74             }75         });76 77         setUndecorated(true);78         setLocationRelativeTo(null);79         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);80     }81 82     public static void main(String[] args) {83         LogANA j = new LogANA();84         j.setVisible(true);85     }86 87 }

 

转载于:https://www.cnblogs.com/aloneblog/p/9638355.html

你可能感兴趣的文章
Oracle中的rownum不能使用大于>的问题
查看>>
cassandra vs mongo (1)存储引擎
查看>>
Visual Studio基于CMake配置opencv1.0.0、opencv2.2
查看>>
遍历Map对象
查看>>
MySQL索引背后的数据结构及算法原理
查看>>
#Leetcode# 209. Minimum Size Subarray Sum
查看>>
SDN第四次作业
查看>>
DM8168 DVRRDK软件框架研究
查看>>
django迁移数据库错误
查看>>
yii 跳转页面
查看>>
洛谷 1449——后缀表达式(线性数据结构)
查看>>
Data truncation: Out of range value for column 'Quality' at row 1
查看>>
Dirichlet分布深入理解
查看>>
(转)Android之发送短信的两种方式
查看>>
python第九天课程:遇到了金角大王
查看>>
字符串处理
查看>>
HtmlUnitDriver 网页内容动态抓取
查看>>
ad logon hour
查看>>
获得进程可执行文件的路径: GetModuleFileNameEx, GetProcessImageFileName, QueryFullProcessImageName...
查看>>
证件照(1寸2寸)拍摄处理知识汇总
查看>>