Flipping square box inside picture help

Hi all, I have an assignment to create a method of the picture class that flips a square box within the picture around a horizontal or vertical line through the middle of the box. (here's an example: pic)

I have worked for a total of 5 hours to only come up with code that does not work, and was wondering if anybody could tell me what I am doing wrong.

The catch here is that I have to do it using the getPixel(x,y) method, nothing simpler will do.

The test file for this program prompts an x, a y, and a size, and the picture repaints itself afterward. Here's the code:

public void flipHorizontal(int x, int y, int size)

{

Pixel a,b,c;

int half = size / 2;

x = x - half;

y = y - half;

int y2 = y;

int x2 = x;

int end = size;

int xend = x + half;

int yend = y + half;

int r,g,bl,r2,g2,b2;

for (y=y2; y < yend; y++)

{

for(x = x2; x < xend+half; x++)

{

a = this.getPixel(x,y);

b = this.getPixel(x,y+end);

r = a.getRed();

g = a.getGreen();

bl = a.getBlue();

r2 = b.getRed();

g2 = b.getGreen();

b2 = b.getBlue();

a.setRed(r2);

a.setGreen(g2);

a.setBlue(b2);

b.setRed(r);

b.setGreen(g);

b.setBlue(bl);

end--;

end--;

}

}

}

any help would be greatly appreciated!

Thanks.