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