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

JAVA HOMEWORK QUESTION: You have a GUI that keeps track of a list of pre-specifi

ID: 3691584 • Letter: J

Question

JAVA HOMEWORK QUESTION: You have a GUI that keeps track of a list of pre-specified "special" points. If the user's mouse moves over one of these points, the point lights up. Write the code that would go inside of the handler/listener below. Use the references and also assume the existence of the method listed below (which you can invoke- you do not need to write).

specialPointList // an ArrayList of the pre-specified "special" points; the type is ArrayList<Point>

assume this method exists: public void lightUpAPoint(Point p)

Your code will go inside the handler method:

public void mouseMoved(MouseEvent event) {

}

Explanation / Answer

/**
The method assumes that lightUpAPoint is exists that method mouseMoved
that gets the x and y positions of the mouse location and use foreach array
and check if point,p location values x and y are equal to mousex and mousey
locations then call the method lightUpAPoint with the point p of specialPointList arraylist
*/

//override mouseMoved method
public void mouseMoved(MouseEvent event)
{
   //Get the x and y locations of mouse
   int mousex=event.getX();
   int mousey=event.getY();

   //run for each loop for each point,p in the specialPointList
   for(Point p:specialPointList )
       {
           //check if x and y values of point,p mathcehs to xmouse and ymouse  
           //then call the method lightUpAPoint
           if(p.getX()==xmouse && p.getY()== ymouse)
               {

                     //call the method lightUpAPoint
                   lightUpAPoint(p);
               }
       }//end of foreach

}//end of mouseMoved