Java By Example PHẦN 4

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 This is the Applet13 applet running under Appletviewer. Listing Printing Instructions in an Applet. import . import . public class Applet13 extends Applet public void paint Graphics g Try to guess the number I am 48 65 thinking of. The number will be 48 80 between 0 and 100. You have an 48 95 unlimited number of tries. 48 110 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 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 Placing the Instructions in a Function. import . import . public class Applet14 extends Applet public void paint Graphics g DrawInstructions g void DrawInstructions Graphics g Try to guess the number I am 48 65 thinking of. The number will be 48 80 between 0 and 100. You have an 48 95 unlimited number of tries. 48 110 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.

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
272    389    1    28-06-2024
Đã 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.