日期:2014-05-20 浏览次数:20751 次
package com.kiritor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JWindow;
public class PFrame extends JWindow {
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean flag = false;
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
private int xx;
private int yy;
private boolean isDraging;
public PFrame() {
}
public PFrame(int x, int y) {
setLocation(x, y);
}
public void showUI() {
setSize(150, 150);
setLayout(null);
setAlwaysOnTop(true);
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
requestFocus();
isDraging = true;
xx = e.getX();
yy = e.getY();
}
public void mouseReleased(MouseEvent e) {
isDraging = false;
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
setFlag(true);// 窗体内部暂时设置为不能取色
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
if (isDraging) {
int left = getLocation().x;
int top = getLocation().y;
setLocation(left + e.getX() - xx, top + e.getY() - yy);
}
}
});
setVisible(true);
}
public static void main(String[] args) {
PFrame frame = new PFrame();
frame.showUI();
}
}