Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 36 of 36

Thread: Image looping issue

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image looping issue

    The images for that print out would be on a row(y=115) going from left to right from 31 to 157.
    What does the print out look like for when the images do not go where you want them to go?

    No need to print values that don't change like Offset and length every time you print. Print them one time before the loop begins.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Mar 2012
    Location
    Billings, MT
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Image looping issue

    That is in fact what the print looks like when the images printed are not where I want them to be. To see my actual visual problem with the images, look here: outrunprint.jpg

    The images are at the moment meant to be in a U shape, though are in an L shape ith only one image printed on the other column.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image looping issue

    images printed are not where I want them to be.
    That print out was for putting images on a row (y=115)
    What did you want that code to do differently? Where were those images supposed to go? What should be the x and y values to put the images where you want them?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Mar 2012
    Location
    Billings, MT
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Image looping issue

    For testing purposes, I wanted the first column to start at y = 10, x = 10 and print 7 times to end up at y = 115, x = 10. The same principal would work for the next column and row. The problem came when only one image was printed at the second column. Basically to me at the moment it does not matter about the coordinates of the images as long as they print a hollow rectangle.

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image looping issue

    I wanted the first column to start at y = 10, x = 10 and print 7 times to end up at y = 115, x = 10.
    If you want the y values to change (keeping the x value constant) then you will be drawing the images in a column.

    What you posted was for the images to be in a row not a column. What does the code and printout look like for when you try to draw images in a column.

    problem came when only one image was printed at the second column.
    Can you show the printout of the x & y values and the code?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    Mar 2012
    Location
    Billings, MT
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Image looping issue

    currentX= 115, currentY = 157 are the values printed out. Let me show you the whole current code so you can see what I am actually talking about.

        private void drawMaze(Graphics2D g){
        	Graphics2D g2 = (Graphics2D)g;
     
                int width = 5; //number of images to be drawn along the x axis.
                int height = 7; //number of images to be drawn along the y axis.
                int xOffset = 21; //width of image.
                int yOffset = 21; //height of image.
                int currentX = 10; //initial positioning of x (10+(21*5)= 115).
                int currentY = 10; //initial positioning of y (to+(21*7)= 157).
                     for(int j = 0; j < height; j++) {
                           g2.drawImage(cobblestone.getImage(), currentX, currentY,this);
                           currentY += yOffset;
     
                           }
                     for(int k = 0; k < width; k++) {
                    	   g2.drawImage(cobblestone.getImage(), currentX, currentY,this);
                    	   currentX += xOffset;
                    	  }
                     System.out.println("currentX= " + currentX + ", currentY = " + currentY);
        }

    I somehow want to implement this strategy for my next column and row. This code only produces an 'L' shape at the moment. I would like it to eventually make a full square.

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image looping issue

    What part of the code works? Which of the four lines are drawn correctly: Left, top, right or bottom?

    Which ones are you having trouble with?


    Your println should be immediately following the call to drawImage so you see where EVERY image is being drawn. For example:

                  // draw first column at constant x 
                  for(int j = 0; j < height; j++) {
    //                       g2.drawImage(cobblestone.getImage(), currentX, currentY,this);
                        System.out.println("currentX= " + currentX + ", currentY = " + currentY);
                        currentY += yOffset;
                  }
                  System.out.println(">>>> Next");
                  // draw row at constant y  
                  for(int k = 0; k < width; k++) {
    //                	   g2.drawImage(cobblestone.getImage(), currentX, currentY,this);
                      System.out.println("currentX= " + currentX + ", currentY = " + currentY);
                 	   currentX += xOffset;
                  }
    Last edited by Norm; June 3rd, 2012 at 01:45 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Member
    Join Date
    Mar 2012
    Location
    Billings, MT
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Image looping issue

    Pretty much all the code I posted you is working at the moment as it is only considering the left and bottom lines. I do not know how to do the top or right lines as each time I try it never works how I anticipate it to.

    Here is the coordinates of every image:

    currentX= 10, currentY = 52
    currentX= 10, currentY = 73
    currentX= 10, currentY = 94
    currentX= 10, currentY = 115
    currentX= 10, currentY = 136
    >>>> Next Line
    currentX= 10, currentY = 157
    currentX= 31, currentY = 157
    currentX= 52, currentY = 157
    currentX= 73, currentY = 157
    currentX= 94, currentY = 157
    >>>> Restart
    currentX= 10, currentY = 10
    currentX= 10, currentY = 31
    currentX= 10, currentY = 52
    currentX= 10, currentY = 73
    currentX= 10, currentY = 94
    currentX= 10, currentY = 115
    currentX= 10, currentY = 136
    >>>> Next Line
    currentX= 10, currentY = 157
    currentX= 31, currentY = 157
    currentX= 52, currentY = 157
    currentX= 73, currentY = 157
    currentX= 94, currentY = 157
    Last edited by Montario; June 3rd, 2012 at 02:21 PM.

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image looping issue

    I do not know how to do the top or right lines
    For the top line:
    What would be the y value for all the images? What would be the range of x values?

    For the right line:
    what would be the x value for all the images? What would be the range of y values?

    If you can answer those questions, you should be able to write the for loops to draw the lines.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    Mar 2012
    Location
    Billings, MT
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Image looping issue

    Thank you Norm, the problem was I kept on mixing up my x and y values which returned a result I did not want. I also declared the variables holding the x and y value changes after the loop was executed.

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image looping issue

    Glad you figured it out. Now on to the next problem.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: February 26th, 2012, 12:57 PM
  2. Create image Jpeg from an object of Image class.
    By Ramandeep in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: December 31st, 2011, 11:34 PM
  3. Re: Help with a looping issue for homework
    By miss doudy in forum Loops & Control Statements
    Replies: 2
    Last Post: December 14th, 2010, 04:07 PM
  4. Help with a looping issue for homework
    By constancez in forum Loops & Control Statements
    Replies: 5
    Last Post: September 20th, 2010, 07:32 AM
  5. Image transparency issue
    By Brt93yoda in forum Java Theory & Questions
    Replies: 6
    Last Post: August 31st, 2010, 02:25 PM