TAILIEUCHUNG - Programming with Java, Swing and Squint phần 7

Menu lựa chọn làm cho bóng tối mùa thu thời gian là "AM" hoặc "PM". Để khám phá một khía cạnh rất cụ thể của mã chương trình như vậy có thể chứa, chúng tôi sẽ xem xét một chương trình hơi ngớ ngẩn mà chỉ chứa một trình đơn được sử dụng để lựa chọn giữa "AM" hoặc "PM". | Figure Selecting daytime from an AM PM menu Figure Menu selection makes darkness fall the time is AM or PM . To explore a very specific aspect of the code that such programs might contain we will consider a somewhat silly program that contains just one menu used to select between AM or PM . This menu will appear alone in a window like the one shown in Figure . During the day it is bright outside. Accordingly when the AM menu item in our program is selected the background of its window will be white as in Figure . On the other hand when the PM menu item is selected the program s window will become pitch black as shown in Figure . A program that implements this behavior is shown in Figure . The code that uses the equals method can be found in the menuItemSelected method. When the user selects either the AM or PM menu item the first line in this method String chosen .toString associates the local variable name chosen with the item that was selected. Then an if statement with the header if AM is used to decide whether to make the background black or white. The equals method will return true only if the String passed as a parameter AM in this example is composed of exactly the same sequence of symbols as the String to which the method is applied chosen. This should all seem quite reasonable but if you think hard about some of the conditions we have included in if statements in other examples the existence of the equals method may strike you as a bit odd. Recall that in many if statements we have used relational operators like and . One of the available relational operators is which we have used to test if two expressions describe the same value. If Java already has why do we also need an equals method Why not simply replace the header of the if statement seen in Figure with 205 A menu driven program that illustrates the use of .equals public class NightAndDay extends GUIManager Dimensions of the programs s .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.