/** --------------------------------------------- * MouseButtons.java * Display program identifying information and handle mouse clicks, passing * them on to the Board class to be processed. * - To run the program start by invoking main() in this class. * * Class: CS 107, Spring 2009 * System: BlueJ 2.5, jsdk 1.6, Windows XP * Program #2, Boggle * * @author Dale Reed * ---------------------------------------------- */ // Import libraries needed by the program import java.util.Scanner; // used for console input import java.io.*; // used for reading from a file import java.awt.event.*; public class MouseButtons implements MouseListener { // Instance variables Board theBoard; // create the board // After x,y values found, add these differences to compensate for screen offsets caused by // title bar on top and screen border on the left final int deltaY = -30; final int deltaX = -4; //---------------------------------------------------------------------------------------- // main() - startup main loop. // "throws IOException" is needed to implement reading from a file public static void main(String[] args) throws IOException { // create an instance of this class MouseButtons MouseButtonsInstance = new MouseButtons(); // Register this instance with Canvas as the MouseListener so mouse events get handled // with the mouse code shown below Canvas.getCanvas().setMouseListener( MouseButtonsInstance); MouseButtonsInstance.doIt(); } // Implementing MouseListener means we must declare the 5 mouse methods: // mouseClicked, mouseEntered, mouseExited, mousePressed, and mouseReleased // We can leave the body empty for methods whose behaviors we do not need to define. // use this to detect mouse "clicks", which is a press (for some milliseconds) & release public void mouseClicked(MouseEvent e) {} // detect mouse position when it enters the drawing frame public void mouseEntered(MouseEvent e) {} // detect mouse position when it exits the drawing frame public void mouseExited(MouseEvent e) {} // detect mouse position when mouse button is pressed public void mousePressed(MouseEvent e) { int x = e.getX() + deltaX; // compensate for offset of frame left border int y = e.getY() + deltaY; // compensate for frame title bar on the tip // pass the mouse click coordinates to the board class to be handled theBoard.handleMouseClick( x,y); } // detect mouse position when mouse button is released public void mouseReleased(MouseEvent e) {} //---------------------------------------------------------------------------------------- // doIt() - display identifying information and run main part of program // void doIt() { // Display identifying information System.out.println( "Author: Dale Reed \n" + "Program #3: Boggle\n" + "October 3, 2009\n"); // Create board theBoard = new Board(); // Display Instructions System.out.println( "Click on the buttons."); }//end method doIt() }//end class MouseButtons