So i have the following code. basically what it does is get current location of x and y. If the user clicks inside the block, move the block so it wont be as jumpy.
public void mouseDragged(MouseEvent arg0) {
Graphics g = getGraphics();
x = arg0.getX();
y = arg0.getY();
if(x>= oldx || x<= oldx+20 && y>=oldy || y<=oldy+20){
g.clearRect(oldx, oldy, 20, 20);
g.fillRect(oldx, oldy+20, 20, 20);
if(arg0.getX() == oldx && arg0.getY() == oldy){
}else{
g.clearRect(oldx, oldy+20, 20, 20);
g.fillRect(arg0.getX(), arg0.getY()+20, 20, 20);
oldx = arg0.getX();
oldy = arg0.getY();
}
}
}