With the mouse listener in hand, you are ready to attach an instance of the
mouse listener to a component using addMouseListener
. One option is
to attach to the meter. Then, a mouse click in the area occupied by
the meter pops up the menu at a point specified by the coordinates
used as arguments in the show
method, relative to the specified
component.
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class MovieApplicationWithPopupMenu extends MovieApplication {
// Define constructor
public MovieApplicationWithPopupMenu () {
// Do what MovieApplication does
super();
// Install popup menu
getMeter().addMouseListener(new MovieMouseListener(this));
}
}