Results 1 to 3 of 3
Thread: Loop with an arraylist
- 01-14-2014, 04:23 PM #1
Member
- Join Date
- Jan 2014
- Posts
- 5
- Rep Power
- 0
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(); } }
- 01-14-2014, 05:39 PM #2
Re: Loop with an arraylist
If you want help, you'll have to provide an SSCCE that demonstrates what you've tried.
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 01-14-2014, 05:50 PM #3
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Loop with an arraylist
First, you created a class Rectangle, not a method. Second, your get methods are counter-intuitive. Gets should just get, nothing more. If you want to increase or decrease the values, then create bump methods or something similar. Third, do what Kevin suggested.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
ArrayList randomly changes after for loop
By dstars5 in forum Advanced JavaReplies: 4Last Post: 10-20-2013, 06:07 PM -
for in while loop and arraylist advanced for
By nonybrighto in forum New To JavaReplies: 4Last Post: 11-20-2012, 03:26 PM -
arrayList in a while loop
By Lund01 in forum New To JavaReplies: 3Last Post: 11-06-2011, 11:28 PM -
How to run a for-each loop through an ArrayList?
By simon.black325 in forum New To JavaReplies: 6Last Post: 09-08-2011, 04:18 AM -
Iterating through ArrayList using For loop
By Java Tip in forum Java TipReplies: 0Last Post: 01-20-2008, 08:53 AM
Bookmarks