Chapter 12 Event-Driven Programming Prerequisi七es王 or part工工工 Chapter 8 Inheritance and Polymorphism Chapter 9 Abstract Classes and Interfaces Chapter 11 Getting Started with GUI Programming hapter 12 Event-Driven Programming 找出画中真谛 一保罗塞尚 hapter 13 Creating User Interfaces Chapter 14 Applets, Images, Audio Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 12 Event-Driven Programming Prerequisites for Part III Chapter 11 Getting Started with GUI Programming Chapter 8 Inheritance and Polymorphism Chapter 13 Creating User Interfaces Chapter 14 Applets, Images, Audio Chapter 9 Abstract Classes and Interfaces Chapter 12 Event-Driven Programming 找出画中真谛 — 保罗.塞尚
Objectives o To explain the concept of event-driven programming($ 12.2) o To understand event, event source, and event classes(8 12.2) To declare listener classes and write the code to handle events (§11.3) o To register listener objects in the source object(8 11.3) ● To understand how an event is handled(§113) ● To write programs to deal with△ Actionevent(§11.3) To write programs to deal with Mouse Event(8 11.4) ● To write programs to deal with Key Event(§115) o To use the Timer class to control animations(8 11.6 Optional) Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 2 Objectives ⚫ To explain the concept of event-driven programming (§12.2). ⚫ To understand event, event source, and event classes (§12.2). ⚫ To declare listener classes and write the code to handle events (§11.3). ⚫ To register listener objects in the source object (§11.3). ⚫ To understand how an event is handled (§11.3). ⚫ To write programs to deal with ActionEvent (§11.3). ⚫ To write programs to deal with MouseEvent (§11.4). ⚫ To write programs to deal with KeyEvent (§11.5). ⚫ To use the Timer class to control animations (§11.6 Optional)
Procedural ys. Event-Driven Programming Procedural programming is executed in procedural order o In oo gui programming, code is executed upon activation of events ● GUIs are event driven O Generate events when user interacts with GUI Oe. g, moving mouse, pressing button, typing in text field, etc o Class java. awt. AWTEvent Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 3 Procedural vs. Event-Driven Programming ⚫ Procedural programming is executed in procedural order. ⚫ In OO GUI programming, code is executed upon activation of events. ⚫ GUIs are event driven Generate events when user interacts with GUI ⚫e.g., moving mouse, pressing button, typing in text field, etc. ⚫Class java.awt.AWTEvent
Events o An event can be defined as a type of signal to the program that something has happened o The event is generated by external user actions such as mouse movements. mouse clicks, and keystrokes, or by the operating system, such as a timer Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 4 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 movements, mouse clicks, and keystrokes, or by the operating system, such as a timer
Event classes Action Event Container event Adjustment Event Focus Event Mouse event entObject AWTEvent Component Event InputEvent ItemEvent Paint event Key event Text event WindowEvent ListSelection Event Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 5 Event Classes EventObject AWTEvent AdjustmentEvent ComponentEvent TextEvent ItemEvent ActionEvent InputEvent WindowEvent MouseEvent KeyEvent ContainerEvent FocusEvent PaintEvent ListSelectionEvent