tailieunhanh - Bài giảng Công nghệ Java: Chương 10 - Lê Nhật Tùng
Bài giảng "Công nghệ Java - Chương 10: Handling mouse and keyboard events - Swing components" cung cấp cho người học các kiến thức: Topics in this section, basic of event handling, delegation model of event, listener type, using separate listener classes, main window implements interface,. . | CÔNG NGHỆ JAVA Handling Mouse and Keyboard Events - SWING components CH10. Giảng viên: Lê Nhật Tùng 4/7/2018 1 Topics in This Section Basic of Event Handling General asynchronous event-handling strategy Event-handling options Handling events with separate listeners Handling events by implementing interfaces Handling events with named inner classes Handling events with anonymous inner classes The standard AWT listener types Subtleties with mouse events Examples 4/7/2018 2 Basic of Event Handling Every time the user types a character or pushes a mouse button, an event occurs. •Events: Objects that describe what happened •Event sources: The generator of an event •Event handlers: A method that receives an event object, deciphers it, and processes the user’s interaction. 4/7/2018 3 Delegation Model of Event An event can be sent to many event handlers. Event handlers register with components when they are interested in events generated by that component. 4/7/2018 4 A Listener Example public class TestButton { JFrame frame; JButton button; public TestButton() { frame = new JFrame("Test"); button = new JButton("Press Me!"); ("ButtonPressed"); // register event listener for button (new ButtonHandler()); (button, ); } public void launchFrame() .
đang nạp các trang xem trước