Hello, I got this final homework program to do for my intro to CS class, but I can't seem to get it working properly.
Basically, there is a 500x500 JPanel that has a 10x10 array of Dot objects in it. In each of those dot objects there is a fillOval to represent a dot. The point of the program is when you click somewhere on the JPanel, a line is drawn between the two closest dots to the click. So it's like a simple version of the game Dots.
My problem is determining which two dots the click was closest to. I've tried using the distance formula to find the closest one, then run through the same loop except specify != the closest (therefore find next closest), but that didn't work. I got some code now that uses the modulus operator on the click coordinates to sorta of place them on the same row/column as the dot (move them to wherever is closest). But that doesn't quite work, since when I click once, it draws a line on everything. When the two closest objects are found, I have them send a boolean of true to either drawUp or drawLeft (since you only need two directions to connect them all, either Up or Left, or Down or Right). I'm not looking for you guys to do my code, but I'm just sorta stuck on what way I should determine the two closest dots.
Basically, there is a 500x500 JPanel that has a 10x10 array of Dot objects in it. In each of those dot objects there is a fillOval to represent a dot. The point of the program is when you click somewhere on the JPanel, a line is drawn between the two closest dots to the click. So it's like a simple version of the game Dots.
My problem is determining which two dots the click was closest to. I've tried using the distance formula to find the closest one, then run through the same loop except specify != the closest (therefore find next closest), but that didn't work. I got some code now that uses the modulus operator on the click coordinates to sorta of place them on the same row/column as the dot (move them to wherever is closest). But that doesn't quite work, since when I click once, it draws a line on everything. When the two closest objects are found, I have them send a boolean of true to either drawUp or drawLeft (since you only need two directions to connect them all, either Up or Left, or Down or Right). I'm not looking for you guys to do my code, but I'm just sorta stuck on what way I should determine the two closest dots.
