Lecture Introduction to Java programming - Chapter 16: Event-driven programming

Suppose you wish to write a GUI program that lets the user enter the loan amount, annual interest rate, and number of years, and click the Compute Loan button to obtain the monthly payment and total payment. How do you accomplish the task? You have to use event-driven programming to write the code to respond to the button-clicking event. | Chapter 16 Event-Driven Programming Motivations Suppose you wish to write a GUI program that lets the user enter the loan amount, annual interest rate, and number of years, and click the Compute Loan button to obtain the monthly payment and total payment. How do you accomplish the task? You have to use event-driven programming to write the code to respond to the button-clicking event. LoanCalculator Run Motivations Suppose you wish to write a program that animates a rising flag, as shown in Figure (b-d). How do you accomplish the task? There are several solutions to this problem. An effective way to solve it is to use a timer in event-driven programming, which is the subject of this chapter. Objectives To describe events, event sources, and event classes (§). To define listener classes, register listener objects with the source object, and write the code to handle events (§). To define listener classes using inner classes (§). To define listener classes using anonymous inner classes (§). To explore various coding styles for creating and registering listeners (§). To get input from text field upon clicking a button (§). To write programs to deal with WindowEvent (§). To simplify coding for listener classes using listener interface adapters (§). To write programs to deal with MouseEvent (§). To write programs to deal with KeyEvent (§). To use the class to control animations (§). Procedural vs. Event-Driven Programming Procedural programming is executed in procedural order. In event-driven programming, code is executed upon activation of events. Revisit Listing Taste of Event-Driven Programming The example displays a button in the frame. A message is displayed on the console when a button is clicked. HandleEvent Run Events An event can be defined as a type of signal to the program that something has happened. The event is generated by external user actions such as mouse . | Chapter 16 Event-Driven Programming Motivations Suppose you wish to write a GUI program that lets the user enter the loan amount, annual interest rate, and number of years, and click the Compute Loan button to obtain the monthly payment and total payment. How do you accomplish the task? You have to use event-driven programming to write the code to respond to the button-clicking event. LoanCalculator Run Motivations Suppose you wish to write a program that animates a rising flag, as shown in Figure (b-d). How do you accomplish the task? There are several solutions to this problem. An effective way to solve it is to use a timer in event-driven programming, which is the subject of this chapter. Objectives To describe events, event sources, and event classes (§). To define listener classes, register listener objects with the source object, and write the code to handle events (§). To define listener classes using inner classes (§). To define listener classes .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
19    248    1    29-04-2024
Đã 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.