TAILIEUCHUNG - Java Programming for absolute beginner- P26

Java Programming for absolute beginner- P26:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | 2 25 03 8 58 AM Page 458 k 0 c c 0 2 V 0 a c E E s k a o k a s s there s no mine in here it reveals the cell and dispatches a event. If there is a mine in here it sets the color to col-ors MINE and dispatches a event. Another anonymous inner class listens for MouseEvents. The superclass JPRButton3D doesn t do anything with right mouse clicks but this MouseAdapter does. It either flags or unflags this cell based on whether the cell is already flagged and dispatches the corresponding event. Another thing the MineCell class needed to take care of was to prevent action events from mine cells that are flagged. You don t want to let the player click a flagged cell and blow up right Nor do you want the cell to be animated. You want it to be concrete that if this cell is flagged you can t click it with the left mouse button period. To accomplish this the MineCell class overrides the processMouseEvent MouseEvent method. If this cell is not flagged or if you re right-clicking it just go ahead and let the MouseEvent pass but if this cell is flagged and you re trying to left-click it stop it dead in its tracks public void processMouseEvent MouseEvent e if flagged e Here is the full source code listing for MineCell Defines one cell of the MinePatrol Game. import . import . import import public class MineCell extends JPRButton3D protected int contents public final static int EMPTY 0 public final static int MINE 9 These colors are indexed by the contents Color EMPTY is for revealed cells and colors MINE is for detonated cells protected Color colors protected boolean hidden detonated flagged acts as the background color when the cell becomes visible protected static Image flagImg mineImg explodeImg protected Vector listeners public MineCell this EMPTY team Line - live .

TỪ KHÓA LIÊN QUAN