Java Programming for absolute beginner- P26
Số trang: 20
Loại file: pdf
Dung lượng: 311.06 KB
Lượt xem: 18
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Java Programming for absolute beginner- P26:Hello and welcome to Java Programming for the Absolute Beginner. You probablyalready have a good understanding of how to use your computer.These days it’s hard to find someone who doesn’t, given the importanceof computers in today’s world. Learning to control your computer intimatelyis what will separate you from the pack! By reading this book, you learnhow to accomplish just that through the magic of programming.
Nội dung trích xuất từ tài liệu:
Java Programming for absolute beginner- P26 JavaProgAbsBeg-12.qxd 2/25/03 8:58 AM Page 458 458 there’s no mine in here, it reveals the cell and dispatches a MineCellEvent.REVEALED event. If there is a mine in here, it sets the color to col- Java Programming for the Absolute Beginner ors[MINE] and dispatches a MineCellEvent.DETONATED event. Another anony- mous 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.getModifiers() == MouseEvent.BUTTON3_MASK) super.processMouseEvent(e); } Here is the full source code listing for MineCell.java: /* * MineCell * Defines one cell of the MinePatrol Game. */ import java.awt.*; import java.awt.event.*; import java.util.Vector; import jpr.lightweight.JPRButton3D; 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 LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-12.qxd 2/25/03 8:58 AM Page 459 459 public MineCell(int contains) { super(); Chapter 12 colors = new Color[] {getBackground(), Color.blue, Color.cyan, Color.green, Color.magenta, Color.yellow, Color.orange, Color.red, Color.black, Color.red.darker().darker()}; setFont(new Font(Arial, Font.BOLD, 16)); resetContents(contains); l ...
Nội dung trích xuất từ tài liệu:
Java Programming for absolute beginner- P26 JavaProgAbsBeg-12.qxd 2/25/03 8:58 AM Page 458 458 there’s no mine in here, it reveals the cell and dispatches a MineCellEvent.REVEALED event. If there is a mine in here, it sets the color to col- Java Programming for the Absolute Beginner ors[MINE] and dispatches a MineCellEvent.DETONATED event. Another anony- mous 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.getModifiers() == MouseEvent.BUTTON3_MASK) super.processMouseEvent(e); } Here is the full source code listing for MineCell.java: /* * MineCell * Defines one cell of the MinePatrol Game. */ import java.awt.*; import java.awt.event.*; import java.util.Vector; import jpr.lightweight.JPRButton3D; 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 LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-12.qxd 2/25/03 8:58 AM Page 459 459 public MineCell(int contains) { super(); Chapter 12 colors = new Color[] {getBackground(), Color.blue, Color.cyan, Color.green, Color.magenta, Color.yellow, Color.orange, Color.red, Color.black, Color.red.darker().darker()}; setFont(new Font(Arial, Font.BOLD, 16)); resetContents(contains); l ...
Tìm kiếm theo từ khóa liên quan:
Nhập môn lập trình lập trình website lập trình ngôn ngữ html giáo trình php lập trình C++Tài liệu có liên quan:
-
Đề cương chi tiết học phần Cấu trúc dữ liệu và giải thuật (Data structures and algorithms)
10 trang 360 0 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 204 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 188 0 0 -
Giáo trình nhập môn lập trình - Phần 22
48 trang 143 0 0 -
[Thảo luận] Học PHP như thế nào khi bạn chưa biết gì về lập trình?
5 trang 138 0 0 -
8 trang 102 0 0
-
Bài giảng Nhập môn lập trình - Chương 12: Quản lý bộ nhớ
23 trang 69 0 0 -
Giáo trình Lập trình Website (Nghề Tin học ứng dụng - Trình độ Cao đẳng) - CĐ GTVT Trung ương I
156 trang 62 2 0 -
Báo cáo đồ án môn học II: Thiết kế website bán đồng hồ
25 trang 56 0 0 -
42 trang 53 0 0