tailieunhanh - Programming with Java, Swing and Squint phần 9

cửa sổ của chương trình sẽ trở thành màu đen như trong hình . Một chương trình mà thực hiện hành vi này được thể hiện trong Hình . Các mã có sử dụng phương pháp tương đương có thể được tìm thấy trong phương pháp menuItemSelected. Khi người dùng lựa chọn hoặc là "AM" hoặc "PM" | Create a Journey containing just the last step Step currentstep startingLoc endingLoc Journey completeRoute new Journey currentStep The variable intermediateLoc will always refer to the current starting point of completeRoute Location intermediateLoc Repeatedly add earlier steps until reaching the starting position while intermediateLoc currentStep startingLoc intermediateLoc completeRoute new Journey currentStep completeRoute intermediateLoc Figure Using the Journey class in a realistic algorithm Recurring Methodically Our Journey class now has all the instance variables and constructors it needs but it does not have any methods. Without methods all we can do with Journeys is construct them and draw lovely diagrams to depict them like Figure . To make the class more useful we need to add a few method definitions. Our Step class included a toString method. It would be helpful to have a similar method for the Journey class. The toString method of the Journey class would create a multi-line String by concatenating together the Strings produced by applying toString to each of the Steps in the Journey placing a newline after the text that describes each step. Such a method would make it easy to display the instructions represented by a Journey in a JTextArea or in some other human-readable form. Since the value returned by applying the toString method to a Journey will usually include multiple lines you might expect the body of the method to contain a loop. In fact no loop will be required. Instead the repetitive behavior the method exhibits will result from the fact that the method like the class in which it is defined will be recursive. Within the body of the toString method we will invoke toString on another Journey object. Case by Case The defintion of a recursive method frequently includes an if statement that reflects the different

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.