最近在做一个项目,要求鼠标左键拖动,可以把图片移动,但是为什么我的左键拖动一直是0.
以下是部分代码:
public void mouseDragged(MouseEvent e) {
this.setCursor(handCursor);
int moveX, moveY;
double tempX, tempY, tempSlope;
moveX = e.getX();
moveY = e.getY();
if (select >= 0) {
// tempX = Math.abs(pointsList.get(select).x + (moveX - x) - width / 2.00);
// tempY = Math.abs(pointsList.get(select).y + (moveY - y) - width / 2.00);
// tempSlope = Math.sqrt(Math.pow(tempX, 2.0) + Math.pow(tempY, 2.0));
tempX = pointsList.get(select).x + (moveX - x) - width / 2.00;
tempY = pointsList.get(select).y + (moveY - y) - width / 2.00;
tempSlope = Math.hypot(tempX, tempY);
int mask = e.getButton();
if (getCursor() == handCursor && (mask & MouseEvent.BUTTON1)!=0) {
// if (getCursor() == handCursor && e.getButton()==MouseEvent.BUTTON1) {
if (width / 2.00 - tempSlope > radiusList.get(select)) {
setList(moveX - x, moveY - y);
} else {
adjustPoint(pointsList.get(select).x + (moveX - x),
pointsList.get(select).y + (moveY - y), radiusList.get(select));
// setList1(roundx, roundy);
setList1(roundx, roundy);
} x = moveX;
y = moveY;
// repaint();
} else if (getCursor() == handCursor && e.isShiftDown()) {
if (width / 2.00 - tempSlope > radiusList.get(select)) {
setList(moveX - x, moveY - y);
del = false;
// repaint();
} else {
setList1(moveX, moveY);
del = true;
// removeItem(select);
// repaint();
}
x = moveX;
y = moveY;
del=false;
} repaint();
}
}
以下是部分代码:
public void mouseDragged(MouseEvent e) {
this.setCursor(handCursor);
int moveX, moveY;
double tempX, tempY, tempSlope;
moveX = e.getX();
moveY = e.getY();
if (select >= 0) {
// tempX = Math.abs(pointsList.get(select).x + (moveX - x) - width / 2.00);
// tempY = Math.abs(pointsList.get(select).y + (moveY - y) - width / 2.00);
// tempSlope = Math.sqrt(Math.pow(tempX, 2.0) + Math.pow(tempY, 2.0));
tempX = pointsList.get(select).x + (moveX - x) - width / 2.00;
tempY = pointsList.get(select).y + (moveY - y) - width / 2.00;
tempSlope = Math.hypot(tempX, tempY);
int mask = e.getButton();
if (getCursor() == handCursor && (mask & MouseEvent.BUTTON1)!=0) {
// if (getCursor() == handCursor && e.getButton()==MouseEvent.BUTTON1) {
if (width / 2.00 - tempSlope > radiusList.get(select)) {
setList(moveX - x, moveY - y);
} else {
adjustPoint(pointsList.get(select).x + (moveX - x),
pointsList.get(select).y + (moveY - y), radiusList.get(select));
// setList1(roundx, roundy);
setList1(roundx, roundy);
} x = moveX;
y = moveY;
// repaint();
} else if (getCursor() == handCursor && e.isShiftDown()) {
if (width / 2.00 - tempSlope > radiusList.get(select)) {
setList(moveX - x, moveY - y);
del = false;
// repaint();
} else {
setList1(moveX, moveY);
del = true;
// removeItem(select);
// repaint();
}
x = moveX;
y = moveY;
del=false;
} repaint();
}
}
楼主【hujie_5592427】截止到2008-08-01 14:44:41的历史汇总数据(不包括此帖):
发帖的总数量:5 发帖的总分数:25 每贴平均分数:5
回帖的总数量:3 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:5 未结的总分数:25
结贴的百分比:0.00 % 结分的百分比:0.00 %
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=hujie_5592427