import java.awt.*; import javax.swing.*; import java.awt.event.*; /** * This class is the listener that tells where on the screen the mouse clicked. */ public class MListener extends MouseAdapter { //Set up JLabels, etc. for the constructor private JLabel theMessage; private JLabel Player; private JButton reset; private int mx3; private int my3; private Game mgame; /** * * @param msg - reference to the theMessage JLabel * @param p - reference to the Player JLabel * @param mx2 - reference to the x coordinate * @param my2 - reference to the y coordinate * @param mgame2 - referece to the Game class */ public MListener(JLabel msg, JLabel p, int mx2, int my2, Game mgame2) { theMessage = msg; Player = p; mx3 = mx2; my3 = my2; mgame = mgame2; } public void mouseClicked(MouseEvent event) { //this code gets and sends the x and y coordinates of a click int mx3 = event.getX(); int my3 = event.getY(); mgame.click(mx3, my3); //theMessage.setText(mx3+","+my3); This will show the x & y coordinates } }