Java中LocationUtil是什么呢,这段代码是什么意思呢
importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.awt.even...
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.lang.reflect.Method;
import javax.swing.JFrame;
public class LocationUtil {
JFrame fram;
private int xx, yy;
private boolean isDraging = false;
public LocationUtil(JFrame frame) {
this.fram = frame;
fram.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
isDraging = true;
xx = e.getX();
yy = e.getY();
System.out.println("========="+xx+":"+yy);
}
public void mouseReleased(MouseEvent e) {
isDraging = false;
}
});
fram.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
if (isDraging) {
int left =fram.getLocation().x;
int top = fram.getLocation().y;
fram.setLocation(left + e.getX() - xx, top + e.getY() - yy);
}
}
});
}
public void setOp(){
try {
Class clazz = Class.forName("com.sun.awt.AWTUtilities");
Method method = clazz.getMethod("setWindowOpaque",
java.awt.Window.class, Boolean.TYPE);
method.invoke(clazz, fram, false);
} catch (Exception e) {
e.printStackTrace();
}
}
} 展开
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.lang.reflect.Method;
import javax.swing.JFrame;
public class LocationUtil {
JFrame fram;
private int xx, yy;
private boolean isDraging = false;
public LocationUtil(JFrame frame) {
this.fram = frame;
fram.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
isDraging = true;
xx = e.getX();
yy = e.getY();
System.out.println("========="+xx+":"+yy);
}
public void mouseReleased(MouseEvent e) {
isDraging = false;
}
});
fram.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
if (isDraging) {
int left =fram.getLocation().x;
int top = fram.getLocation().y;
fram.setLocation(left + e.getX() - xx, top + e.getY() - yy);
}
}
});
}
public void setOp(){
try {
Class clazz = Class.forName("com.sun.awt.AWTUtilities");
Method method = clazz.getMethod("setWindowOpaque",
java.awt.Window.class, Boolean.TYPE);
method.invoke(clazz, fram, false);
} catch (Exception e) {
e.printStackTrace();
}
}
} 展开
展开全部
isDraging
使用一个属性作为开关,(自己想想没有开关控制会怎么样)
fram.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
isDraging = true;
xx = e.getX();
yy = e.getY();
System.out.println("========="+xx+":"+yy);
}这段代码就是,添加一个鼠标监听器,当鼠标按下的时候,获取光标的坐标,
public void mouseReleased(MouseEvent e) {
isDraging = false;
}在鼠标移开的时候,将isDraging职位false(开关关闭),
fram.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
if (isDraging) {
int left =fram.getLocation().x;
int top = fram.getLocation().y;
fram.setLocation(left + e.getX() - xx, top + e.getY() - yy);
这段代码说的是鼠标拖拽的时候,光标的坐标变化
首先获取原始的光标的坐标,然后加上拖拽的横纵坐标,得到最后的坐标
public void setOp(){
try {
Class clazz = Class.forName("com.sun.awt.AWTUtilities");
Method method = clazz.getMethod("setWindowOpaque",
java.awt.Window.class, Boolean.TYPE);
method.invoke(clazz, fram, false);
} catch (Exception e) {
e.p }这段代码是使用动态代理的方法得到com.sun.awt.AWTUtilities 对象,方法,并调用
使用一个属性作为开关,(自己想想没有开关控制会怎么样)
fram.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
isDraging = true;
xx = e.getX();
yy = e.getY();
System.out.println("========="+xx+":"+yy);
}这段代码就是,添加一个鼠标监听器,当鼠标按下的时候,获取光标的坐标,
public void mouseReleased(MouseEvent e) {
isDraging = false;
}在鼠标移开的时候,将isDraging职位false(开关关闭),
fram.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
if (isDraging) {
int left =fram.getLocation().x;
int top = fram.getLocation().y;
fram.setLocation(left + e.getX() - xx, top + e.getY() - yy);
这段代码说的是鼠标拖拽的时候,光标的坐标变化
首先获取原始的光标的坐标,然后加上拖拽的横纵坐标,得到最后的坐标
public void setOp(){
try {
Class clazz = Class.forName("com.sun.awt.AWTUtilities");
Method method = clazz.getMethod("setWindowOpaque",
java.awt.Window.class, Boolean.TYPE);
method.invoke(clazz, fram, false);
} catch (Exception e) {
e.p }这段代码是使用动态代理的方法得到com.sun.awt.AWTUtilities 对象,方法,并调用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询