java - Drag/Moving a shape around jPanel -


yesterday ask question how draw bounding box hold shape inside , how drag , drop selected shape.

the first question solved. i'm having trouble move shape. there especific transformations move shape around jpanel?

i have code:

public boolean drag(mouseevent e) {     if(points.isempty()) //if point's vector empty         return false;      if(!selected)         return false;      int x = e.getx(), y = e.getx();      if (!dragging)         lastmovepoint.setlocation(x, y);      dragging = true;      int deslocx = 0;     int deslocy = 0;      int oldx = -1;     int oldy = -1;      int size = points.size();     for(int = 0; < size; i++) {         oldx = lastmovepoint.x;         oldy = lastmovepoint.y;          deslocx = x - oldx;         deslocy = y - oldy;          points.set(i, new point(points.get(i).x + deslocx, points.get(i).y + deslocy)); //set vector of points when there repaint() repaints shape new //coordinates       }      lastmovepoint.setlocation(x, y); //set location of old point     return true; } 

this method called listener mousedragged , return true in case of sucess. i'm trying add difference between previous point of dragg , actual.

when run code have problem:

the shape goes right/left, , down not working...

.

int x = e.getx(), y = e.getx(); 

this should changed

int x = e.getx(), y = e.gety(); 

that's why works in x direction, aren't taking account y direction


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -