Object Oriented Programming using Java phần 7

Biến, điều này được sử dụng trong mã nguồn của một phương pháp dụ để tham khảo cho các đối tượng có chứa các phương pháp. Mục đích của tên này, này, là để tham khảo "đối tượng này", một trong những quyền ở đây là phương pháp này rất là. | Create MouseListener object. RepaintOnClick listener new RepaintOnClick Create MouseListener object . listener Once this is done the listener object will be notified of mouse events on the panel. Whenever a mousePressed event occurs the mousePressed method in the listener will be called. The code in this method calls the repaint method in the component that is the source of the event that is in the panel. The result is that the RandomStringsPanel is repainted with its strings in new random colors fonts and positions. Although the RepaintOnClick class was written for use with the RandomStringsPanel example the event-handling class contains no reference at all to the RandomStringsPanel class. How can this be The mousePressed method in class RepaintOnClick looks at the source of the event and calls its repaint method. If we have registered the RepaintOnClick object as a listener on a RandomStringsPanel then it is that panel that is repainted. But the listener object could be used with any type of component and it would work in the same way. Similarly RandomStringsPanel contains no reference to the RepaintOnClick classin fact RandomStringsPanel was written before we even knew anything about mouse events The panel will send mouse events to any object that has registered with it as a mouse listener. It does not need to know anything about that object except that it is capable of receiving mouse events. The relationship between an object that generates an event and an object that responds to that event is rather loose. The relationship is set up by registering one object to listen for events from the other object. This is something that can potentially be done from outside both objects. Each object can be developed independently with no knowledge of the internal operation of the other object. This is the essence of modular design Build a complex system out of modules that interact only in straightforward easy to understand ways. Then each module is

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.