In java language You have a GUI that keeps track of a list of pre-specified \"sp
ID: 3690740 • Letter: I
Question
In java language
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
Public void lightUpAPoint( (Point p) {
point_highlight = p; // point_hightlight determines if the highlight is enables or not and to highlight when the mouse moves over the point p
repaint();
Container parenthere = getParent(); // This is used to get the parent
if (parenthere == null) {
return;
}
Component[] compsone = parent.getComponents();
for (int i = 0; i < compsone.length; ++i) {
if (compsone[i] instanceof GameBoardPanel) {
GameBoardPanel panelhere = (GameBoardPanel)compshere[i];
// it hovers the mouse over the gameboard panel and highlights when a point p is found.This basically traverses the entire gameboard to find the point.
panelhere.point_highlight = p;
panelhere.repaint();
}
}
}
}
Public void lightUpAPoint( (Point p) {
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.