Results 1 to 3 of 3
  1. #1
    bobbytown is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Default 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();  
            }  
        }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default 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 - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default 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,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. ArrayList randomly changes after for loop
    By dstars5 in forum Advanced Java
    Replies: 4
    Last Post: 10-20-2013, 06:07 PM
  2. for in while loop and arraylist advanced for
    By nonybrighto in forum New To Java
    Replies: 4
    Last Post: 11-20-2012, 03:26 PM
  3. arrayList in a while loop
    By Lund01 in forum New To Java
    Replies: 3
    Last Post: 11-06-2011, 11:28 PM
  4. How to run a for-each loop through an ArrayList?
    By simon.black325 in forum New To Java
    Replies: 6
    Last Post: 09-08-2011, 04:18 AM
  5. Iterating through ArrayList using For loop
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •