can somebody tell me what this code actually does?

int i = 0;
		while (i < -1) {
			double x = xCoordinates[i];
			double y = yCoordinates[i];

			long xx = getWidth() - Math.round((double) getWidth() * x / 1024.0);
			long yy = getHeight()- Math.round((double) getHeight() * y / 768.0);
			g2.translate(xx, yy);

			g2.setPaint(borderColor);
			
		        g2.fill(shape);
			g2.setTransform(new AffineTransform());
     

			i++;


                     

		}
		
		g.drawImage(mImage, 0, 0, null);
	}

i am mostly intrested in lines 6,7,8 and 13
thanks

Recommended Answers

All 6 Replies

They don't do anything because of lines 1 and 2.

You can read what translate() does here: http://download.oracle.com/javase/6/docs/api/java/awt/Graphics2D.html#translate(int,%20int)

Line 13 is a (somewhat inefficient and perhaps ill-fated) way of resetting back to the default starting point of your coordinate system.

Lines 2,3,4 also suspect, the array references will only be executed if the array index is negative and therefore out of bounds.

6,7 seem to take xy coords in the range 1024,768 and scale them to fit the actual size of the current component. They also invert them so the origin is the bottom right corner (seems normal for y, unusual for x - I would expect bottom LH corner)

sorry for such a late reply, thanks a lot for this explanation it does make the code clearer thank you

hey guys again, well what this program actually does is sets points in the different loacations of the image and what i need to do is draw a line between those points but i have no idea how to do it because im unable to grab the coordinates of the second point and draw the line between the first one and the second one.
any suggestions?
thanks

I think this is anew topic and deserves its own thread, but... there's no way to answer this without a lit more info about where the points come from - a file? user mouse clicks?
Suggest you start a new thread and describe the situation in much more detail.
J

ok ill just start a new thread thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.