0
所以我想要做的是一鍵後保持mousePressed方法'開',即使我沒有按住自己。然後接一個地點擊它會打開「關閉」保持鼠標按下活動後點擊一下
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
// save coord x,y when mouse is pressed
oldX = e.getX();
oldY = e.getY();
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
// coord x,y when drag mouse
currentX = e.getX();
currentY = e.getY();
if (g2 != null) {
// draw oval if g2 context not null
g2.drawOval(oldX, oldY, width, height);
g2.fillOval(oldX, oldY, width, height);
// refresh draw area to repaint
repaint();
// store current coords x,y as olds x,y
oldX = currentX;
oldY = currentY;
}
}
});
使用布爾字段..瞭解它是否被點擊了不... –
設置一個布爾標誌(或跟蹤點擊次數和使用模塊化數學)並監視mouseMoved事件 – MadProgrammer