posted 19 years ago
You basically need to turn mouse events into word selection events, as it appears you've started above. As a first design I would do the following. Note that a grid cell is denoted by its row and column.
mousePressed(): Save starting grid cell, change background of starting cell to some highlight color. Set tracking cell to starting cell.mouseMoved(): If new cell is the same as the tracking cell -- user is in the same cell as the last update, exit method without doing anything more. Otherwise, set tracking cell to new cell and set the background colors of all cells between the starting and tracking cell to the highlight color. If the line of cells from starting cell to tracking cell don't make up a valid line (aren't perfectly horizontal, vertical, or diagonal), highlight only the starting cell. Make sure you clear the backgrounds of the previously highlighted cells if they shouldn't still be highlighted.mouseReleased(): Clear all highlighting. If the line of cells from starting cell to tracking cell is valid, the user has selected a word. Perform any other validation you need to do and exit.