Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Introduction to Java programming - Chapter 16: Event-driven programming

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

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 16.1(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 (§16.2). To define listener classes, register listener objects with the source object, and write the code to handle events (§16.3). To define listener classes using inner classes (§16.4). To define listener classes using anonymous inner classes (§16.5). To explore various coding styles for creating and registering listeners (§16.6). To get input from text field upon clicking a button (§16.7). To write programs to deal with WindowEvent (§16.8). To simplify coding for listener classes using listener interface adapters (§16.9). To write programs to deal with MouseEvent (§16.10). To write programs to deal with KeyEvent (§16.11). To use the javax.swing.Timer class to control animations (§16.12). 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 11.7 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 16.1(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 (§16.2). To define listener classes, register listener objects with the source object, and write the code to handle events (§16.3). To define listener classes using inner classes (§16.4). To define listener classes .

Đã 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.