Question: 12.2 Steps to Code Event Delegation 1. import java.awt.event.* 2. implements the appropriate interface from the defined class Eg: implements ActionListener 3. Register GUI component



12.2 Steps to Code Event Delegation 1. import java.awt.event.* 2. implements the appropriate interface from the defined class Eg: implements ActionListener 3. Register GUI component to the appropriate listener - Eg: button.addActionListener(this); 4. Implements interface method - Eg : public void actionPerformed (ActionEvent e) {...} Page 141 12 EVENT HANDLING 12.3 Example of Event Handling The following code demonstrates a GUI to display "Java is fun and easy" when the user clicks on Press Me button as shown in Figure 12-1. import java.awt.BorderLayout; import java.awt.event. ActionEvent; import java.awt.event. ActionListener; Exercise 1 1. Using Point of Sales GUI developed from Lab 9 (refer to Figure 12-2), code the following requirements. Point of Sales OX Crunchy Combo 1 - RM 19.70 O Crunchy Combo 2 - RM 26.90 O Hot Variety Box - RM 28.28 Hot Power Meal 1 - RM 22.90 Hot Power Meal 2 - RM 53.90 Select Item : Quantity quantity: Payment Method: Visa Credit card number: DONE! Figure 12-2: GUI of Point of Sales a. User can select only 1 item at one time. b. The quantity should be numbers only. c. Credit card number should be number only. d. Point of Sales will calculate the amount of sales when the user clicks Done. Point of Sales displays an output as shown in Figure 12-3. f. The text area is not editable. e 12 EVENT HANDLING Point of Sales Crunchy Combo 1 - RM 19.70 O Crunchy Combo 2 - RM 26.90 Hot Variety Box - RM 28.28 O Hot Power Meal 1 - RM 22.90 Hot Power Meal 2 - RM 53.90 Select Item: Quantity quantity : 5 Payment Method: Master Credit card number: 345665-4545-0867 DONE! Selected Item Price Per Unit: Hot Power Meal 1 - RM 22.90 Quantity: 5 The amount is RM 114.5 charged to Master 345665-4545-0867 Figure 12-3: Point of Sales with output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
