Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Working with Java for the first time. I\'m supposed to draw a grid, and each tim

ID: 3635980 • Letter: W

Question

Working with Java for the first time. I'm supposed to draw a grid, and each time the mouse clicks, the grid chooses a random red dot and changes the color of it and its "neighbors " from red to green if they are not already green. I have worked out the grid part (below) and I think I have the logic for the second part. I need to choose a random array and to check its "neighbors" I have to take the array and add or subtract one and then check that dot.I was able to create the 2D dot grid array just fine but came up with a problem onMouseClick. How to check the neighbors color and change accordingly so that after several clicks the whole grid becomes a single colored grid. Please Help. Thank You!!

Explanation / Answer

Hi, answering here for the first time. You have to first obtain the coordinates of the dot that has been modified. Since it is a grid, its neighbors will be at a regular distance.if you have created the dot grid's instances using a graphics object array, you need to identify the co-relation between the dot and its neighboring dots. The ones in the same row are easy to locate. You can use their X and Y co-ordinates, to trace the nighboring cell using the regular distance between the dots.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote