Đang chuẩn bị liên kết để tải về tài liệu:
Java By Example PHẦN 4

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Làm thế nào sâu sắc mà bạn có thể khai thác phụ thuộc vào sự phức tạp của sự biểu hiện ban đầu. Tuy nhiên, như bạn thấy chứng minh, ngay cả những biểu hiện tương đối đơn giản num = (5 - x) * (2 + y) có bốn cấp độ về chiều sâu. | Figure 12.1 This is the Applet13 applet running under Appletviewer. Listing 12.1 Applet13.java Printing Instructions in an Applet. import java.awt. import java.applet. public class Applet13 extends Applet public void paint Graphics g g.drawString Try to guess the number I am 48 65 g.drawString thinking of. The number will be 48 80 g.drawString between 0 and 100. You have an 48 95 g.drawString unlimited number of tries. 48 110 g.drawString Good Luck. 95 140 Applet13 is about the simplest applet you can write. All it does is display text. The text comprises instructions for playing a simple number game. If you had to sum up in a couple of words the task performed by Applet13 s paint method you might come up with something like Draw Instructions which is an excellent name for a function to handle that task. Listing 12.2 is a new version of the applet that isolates the instruction-display task in its own function. When you run this applet it looks identical to Applet13. Listing 12.2 Applet14.java Placing the Instructions in a Function. import java.awt. import java.applet. public class Applet14 extends Applet public void paint Graphics g DrawInstructions g void DrawInstructions Graphics g g.drawString Try to guess the number I am 48 65 g.drawString thinking of. The number will be 48 80 g.drawString between 0 and 100. You have an 48 95 g.drawString unlimited number of tries. 48 110 g.drawString Good Luck. 95 140 Now for the million-dollar question How does this Applet14 work The program is divided into two functions. The first is the paint method which Java calls whenever the applet s display area must be redrawn. In this applet paint is at the highest level of your top-down design. That is no other part of the program calls paint but paint calls functions that are lower in level. NOTE You might be confused about the difference between methods functions and subroutines. The truth is that they are very similar. Specifically a method is a function that is part of a class.

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.