TAILIEUCHUNG - Introduction to Java: 4 -Events

Tham khảo tài liệu 'introduction to java: 4 -events', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 4 In this chapter Java Event Model The Event Class The Java Event Model Events This chapter covers Java s event-driven programming model. Unlike procedural programs windows-based programs require an event-driven model in which the underlying environment tells your program when something happens. For example when the user clicks on the mouse the environment generates an event that it sends to the program. The program must then figure out what the mouse click means and act accordingly. This chapter covers two different event models or ways of handling events. In Java and earlier events were passed to all components that could possibly have an interest in them. Events themselves were encapsulated in a single Event class. Java implements a delegation model in which events are distributed only to objects that have been registered to receive the event. While this is somewhat more complex it is much more efficient and also more flexible because it allows any object to receive the events generated by a component. In turn this means that you can separate the user interface itself from the event-handling code. In the Java event model all event functionality is contained in a new package . Within this package subclasses of the abstract class AWTEvent represent different kinds of events. The package also includes a number of EventListener interfaces that are implemented by classes that want to receive different kinds of events they define the methods that are called when events of the appropriate type occur. A number of adapter classes are also included they correspond to the EventListener interfaces and provide null implementations of the methods in the corresponding listener. The adapter classes aren t essential but provide a convenient shortcut for developers rather than declaring that your class implements a particular EventListener interface you can declare that your class extends the appropriate adapter. 94 Java Event Model 95

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