Tuesday, January 14, 2014

Loop with an arraylist


I have created a method Rectangle and added a loop in my class Resizer (MouseAdapter) but impossible to resize the rectangles of the arraylist independantly.



Java Code:



class Rectangle extends Rectangle2D.Float{

private String name;

public Rectangle(float x, float y, float width, float height, String name) {
setRect(x, y, width, height);
this.name = name;
}
public String getName() {
return name;
}
public void getX(float x) {
this.x += x;
}
public void getY(float y) {
this.y += y;
}
public void getWidth(float width) {
this.width += width;
}
public void getHeight(float height) {
this.height += height;
}

}


Java Code:



@Override
public void mouseDragged(MouseEvent e) {
if(dragging) {
Point p = e.getPoint();
for (int j=0;j<1;j++) {
Rectangle r = paths.get(j);
float dy = p.y - r.y;
float height = r.height - dy;
r.setRect(r.x, r.y+dy, r.width, height);
}
for (int j=1;j<2;j++) {
Rectangle r = paths.get(j);
float dy = p.y - r.y;
float height = r.height - dy;
r.setRect(r.x, r.y+dy, r.width, height);
}
component.repaint();
}
}


No comments:

Post a Comment