Java Programming for absolute beginner- P24
Số trang: 20
Loại file: pdf
Dung lượng: 370.18 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- P24: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- P24 JavaProgAbsBeg-11.qxd 2/25/03 8:57 AM Page 418 418 character at a time using the reader.read() method. If the end of the file (EOF) is reached, this method returns –1. So the while loop checks for this as its con- Java Programming for the Absolute Beginner dition. Although each character read in is not –1, write that character to the writer buffer anyway. Invoking the writer.close() causes the buffer to be cleared, written to the file, and closed. Figure 11.6 shows one run of the FileCopy application. FIGURE 11.6 The FileCopy application copied the file1.txt file and saved the copy as copy.txt. P Don’t forget to call the close() method on the BufferedWriter. If you don’t you TRA won’t get any actual output. There is also a method called flush() which flush- es the buffer and writes it out to the file, but calling close() actually flushes the buffer before closing anyway. Keeping Score The ScoreInfoPanel class keeps score basically by keeping track of three integers: scoreValue keeps track of the current score, hiValue keeps track of the high score, and nLinesValue keeps track of the number of lines cleared. The ScoreInfoPanel class also provides methods for modifying these values such as setScore(int), setHiScore(int), and setLines(int) for setting these values to the given int value. It also provides addToScore(int) and addToLines(int) TEAM LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-11.qxd 2/25/03 8:57 AM Page 419 419 methods for adding the given int value to these values. Here is the source code for ScoreInfoPanel.java: Chapter 11 /* * ScoreInfoPanel * A Panel that shows the scoring info for a BlockGame * and shows the next block. */ import java.awt.*; Custom Event Handling and File I/O import java.io.*; import java.text.NumberFormat; public class ScoreInfoPanel extends Panel { protected Label scoreLabel = new Label(Score: ), linesLabel = new Label(Lines: ), score = new Label(), hiLabel = new Label(), lines = new Label(), nextLabel = new Label(Next Block, Label.CENTER); protected int scoreValue = 0, hiValue = 0, nLinesValue = 0; protected BlockGrid nextBlockDisplay = new BlockGrid(6, 6, 10); public static int BLOCK = 1, ROW1 = 100, ROW2 = 300, ROW3 = 600, ROW4 = 1000, ROW4BONUS = 10000; protected Label[] points = { new Label(Block = + BLOCK + points), new Label(1 Row = + ROW1 + points), new Label(2 Rows = + ROW2 + points), new Label(3 Rows = + ROW3 + points), new Label(4 Rows = + ROW4 + points), new Label(BONUS = + ROW4BONUS + points) }; NumberFormat nf = NumberFormat.getInstance(); Block block = null; public ScoreInfoPanel() { ...
Nội dung trích xuất từ tài liệu:
Java Programming for absolute beginner- P24 JavaProgAbsBeg-11.qxd 2/25/03 8:57 AM Page 418 418 character at a time using the reader.read() method. If the end of the file (EOF) is reached, this method returns –1. So the while loop checks for this as its con- Java Programming for the Absolute Beginner dition. Although each character read in is not –1, write that character to the writer buffer anyway. Invoking the writer.close() causes the buffer to be cleared, written to the file, and closed. Figure 11.6 shows one run of the FileCopy application. FIGURE 11.6 The FileCopy application copied the file1.txt file and saved the copy as copy.txt. P Don’t forget to call the close() method on the BufferedWriter. If you don’t you TRA won’t get any actual output. There is also a method called flush() which flush- es the buffer and writes it out to the file, but calling close() actually flushes the buffer before closing anyway. Keeping Score The ScoreInfoPanel class keeps score basically by keeping track of three integers: scoreValue keeps track of the current score, hiValue keeps track of the high score, and nLinesValue keeps track of the number of lines cleared. The ScoreInfoPanel class also provides methods for modifying these values such as setScore(int), setHiScore(int), and setLines(int) for setting these values to the given int value. It also provides addToScore(int) and addToLines(int) TEAM LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-11.qxd 2/25/03 8:57 AM Page 419 419 methods for adding the given int value to these values. Here is the source code for ScoreInfoPanel.java: Chapter 11 /* * ScoreInfoPanel * A Panel that shows the scoring info for a BlockGame * and shows the next block. */ import java.awt.*; Custom Event Handling and File I/O import java.io.*; import java.text.NumberFormat; public class ScoreInfoPanel extends Panel { protected Label scoreLabel = new Label(Score: ), linesLabel = new Label(Lines: ), score = new Label(), hiLabel = new Label(), lines = new Label(), nextLabel = new Label(Next Block, Label.CENTER); protected int scoreValue = 0, hiValue = 0, nLinesValue = 0; protected BlockGrid nextBlockDisplay = new BlockGrid(6, 6, 10); public static int BLOCK = 1, ROW1 = 100, ROW2 = 300, ROW3 = 600, ROW4 = 1000, ROW4BONUS = 10000; protected Label[] points = { new Label(Block = + BLOCK + points), new Label(1 Row = + ROW1 + points), new Label(2 Rows = + ROW2 + points), new Label(3 Rows = + ROW3 + points), new Label(4 Rows = + ROW4 + points), new Label(BONUS = + ROW4BONUS + points) }; NumberFormat nf = NumberFormat.getInstance(); Block block = null; public ScoreInfoPanel() { ...
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