Đang chuẩn bị liên kết để tải về tài liệu:
Java Programming for absolute beginner- P23

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Java Programming for absolute beginner- P23:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | JavaProgAbsBeg-11.qxd 2 25 03 8 57 AM Page 398 Registering PlayAreaListeners q The registering of PlayAreaListeners takes place in the PlayArea class. You won t c see the entire source listing for PlayArea.java until a bit later but I feel it is most relevant to discuss how it registers listeners here and how it fires events in the w CO next section Firing PlayAreaEvents. Registering the listeners is not that com- plicated. Basically PlayArea uses a Vector to maintain a dynamic list of PlayAre- 5 aListeners 0 q protected Vector listeners The PlayArea class also provides two methods for updating this Vector object addPlayAreaListener PlayAreaListener and removePlayAreaListener Pla-q yAreaListener . addPlayAreaListener PlayAreaListener adds the passed PlayAreaListener any class that implements the PlayAreaListener interface to C listeners and removePlayAreaListener PlayAreaListener removes the speciE fied PlayAreaListener. Here is what they look like j public void addPlayAreaListener PlayAreaListener pal gi listeners.addElement pal 0 C public void removePlayAreaListener PlayAreaListener pal listeners.removeElement pal J You can see that they work just by calling the Vector class s methods. That s all it takes. Now you have a list of nosy classes that you need to notify when you fire PlayAreaEvents. Firing PlayAreaEvents You fire PlayAreaEvents from the PlayArea class by creating an instance of the PlayAreaEvent class and then calling the registered PlayAreaListeners block-Landed BlockEvent methods. The PlayArea class has a private method for doing this private void fireBlockLanded PlayAreaEvent pae for int l 0 l listeners.size l PlayAreaListener listeners.elementAt l .blockLanded pae fireBlockLanded PlayAreaEvent loops on the elements in the listeners Vector and calls their blockLanded PlayAreaEvent methods passing in the given pae reference. As you can see the PlayAreaEvent object must be created prior to calling fireBlockLanded PlayAreaEvent . It does this by .

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.