写一个无边框JFrame,并使其拖动
来源:互联网 发布:南京鸿鸣网络科技知乎 编辑:程序博客网 时间:2024/06/06 14:10
package DeskTop;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Note extends JFrame implements MouseListener,MouseMotionListener{
private JLabel iconLabel;
private JPanel firstpPanel;
private ImageIcon backIcon;
public Note() {
backdrop();
}
private void backdrop() {
//搭建背景,容器
setUndecorated(true);
backIcon = new ImageIcon("backdrop1.gif");
iconLabel = new JLabel(backIcon);
iconLabel.setBounds(0, 0,backIcon.getIconWidth(),backIcon.getIconHeight());
firstpPanel = (JPanel)this.getContentPane();
getLayeredPane().setLayout(null);
getLayeredPane().add(iconLabel, new Integer(Integer.MIN_VALUE));
firstpPanel.setOpaque(false);
//AWTUtilities.setWindowOpacity(this, 0.5f);
setSize(backIcon.getIconWidth(),backIcon.getIconHeight());
/*AWTUtilities.setWindowShape(this, new RoundRectangle2D.Double(
0.0D, 0.0D, this.getWidth(), this.getHeight(), 80.0D,
30.0D));*/
setLocation(80, 80);
setVisible(true);
addMouseListener(this);
addMouseMotionListener(this);
}
public static void main(String[] args) {
new Note();
}
Boolean tBoolean = false;
Point fPoint;
Point sPoint;
Point tPoint;
private void move() {
Double fx,fy;
Double sx,sy;
Double tx,ty;
fx = fPoint.getX(); fy = fPoint.getY();
sx = sPoint.getX(); sy = sPoint.getY();
tx = tPoint.getX(); ty = tPoint.getY();
fPoint.setLocation(fx+tx-sx, fy+ty-sy);
setLocation(fPoint);
}
public void mouseDragged(MouseEvent e) {
//tBoolean = true;
//System.out.println("ddddd");
tPoint = e.getPoint();
move();
}
public void mousePressed(MouseEvent e) {
fPoint = getLocation();
sPoint = e.getPoint();
}
public void mouseMoved(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
}
- 写一个无边框JFrame,并使其拖动
- 拖动去掉边框的JFrame
- JFrame实现无边框 及 实现拖动和Button关闭功能
- MFC使无边框对话框可拖动
- c# 无边框拖动
- 无边框窗口拖动
- 无边框窗体拖动
- 无边框窗体拖动
- 无i边框拖动
- WPF 无边框拖动
- QT 窗口设置成无边框并实现拖动
- Java程序中取消窗口标题栏以及边框,并使窗口可以相应鼠标事件,被鼠标拖动;设置JFrame背景色
- Java JFrame实现无边框无标题
- 无边框窗体拖动大小
- 如何拖动无边框窗体
- 无边框窗体拖动大小
- 无边框窗口拖动问题
- 无边框的窗体拖动
- C# Enum,Int,String的互相转换 枚举转换
- object_c随机数的生成(3种:arc4random() 、random()、CCRANDOM_0_1() )
- Linux Kickstart无人值守
- ASP.NET MVC3 快速入门-第一节 概述
- 判断sqlite数据库中表是否存在的方法
- 写一个无边框JFrame,并使其拖动
- 在副线程中LoadString失败解决办法
- C++笔记1
- Javascript 跨浏览器事件
- Eclipse发布程序
- HTML <select> 标签
- 合泰 HT66F04 IO初始化
- redo、dirty data、commit、checkpoint理解
- UITabBarController