java鼠标拖动事件问题
请高手看看下面的程序,设置按钮坐标的地方如果改成相对事件源,拖的时候就会出现两个按钮,这是怎么回事啊?请高人指点importjava.applet.*;importjav...
请高手看看下面的程序,设置按钮坐标的地方如果改成相对事件源,拖的时候就会出现两个按钮,这是怎么回事啊?请高人指点
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Task_6 extends Applet implements MouseMotionListener{
Button b;
public Task_6(){
resize(500,400);
b = new Button("拖我");
b.addMouseMotionListener(this);
add(b);
setVisible(true);
}
public void mouseDragged(MouseEvent e){
//b.setLocation(e.getPoint());
b.setLocation(e.getLocationOnScreen());
//b.setLocation(e.getX(),e.getY());
b.setLocation(e.getXOnScreen()-10,e.getYOnScreen()-50);
//System.out.println(e.getX()+e.getY());
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
//b.setLocation(e.getPoint());
}
} 展开
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Task_6 extends Applet implements MouseMotionListener{
Button b;
public Task_6(){
resize(500,400);
b = new Button("拖我");
b.addMouseMotionListener(this);
add(b);
setVisible(true);
}
public void mouseDragged(MouseEvent e){
//b.setLocation(e.getPoint());
b.setLocation(e.getLocationOnScreen());
//b.setLocation(e.getX(),e.getY());
b.setLocation(e.getXOnScreen()-10,e.getYOnScreen()-50);
//System.out.println(e.getX()+e.getY());
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
//b.setLocation(e.getPoint());
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询