写一个无边框JFrame,并使其拖动

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) {
  
 }
 

}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值