Lecture An introduction to computer science using java (2nd Edition): Chapter 11 - S.N. Kamin, D. Mickunas, E. Reingold

Chapter 11 - Java AWT part I: Mouse events (Optional). In this chapter we will: introduce event driven programming, show how a program can respond to mouse events (. clicks and mouse movements), demonstrate how to implement a listener interface, show how mouse events can be used to build highly interactive programs. | Chapter 11 Java AWT Part I: Mouse Events (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: introduce event driven programming show how a program can respond to mouse events (. clicks and mouse movements) demonstrate how to implement a listener interface show how mouse events can be used to build highly interactive programs Abstract Windowing Toolkit (AWT) Part of the Java distribution, but not part of the Java language itself AWT is library of classes and methods used by Java programmers that supported are by the basic Java runtime libraries Even though this chapter is labeled optional, it is not possible to be a complete Java programmer without understanding the AWT Java Events Events are occurrences outside of the program to which the program must respond (. user key press) Event managers are methods that first catch the event Listener classes send messages to an event manager requesting to be notified when a particular message occurs Event managers send messages to listeners notifying them when a particular event occurs Creating Mouse Click Listeners Import the package In the class header, add the words implements MouseListener Send the addMouseListerner(this) message to the mouse event manager (should be done in the constructor method) Define methods mouseClicked, mousePressed, mouseReleased, mouseEntered, mouseExited Mouse Click Listener Template import .*; public class classname implements MouseListener { // include (this); // in some initialization method public void mouseClicked (MouseEvent e) { } public void mousePressed (MouseEvent e) { } public void mouseReleased (MouseEvent e) { } public void mouseEntereded (MouseEvent e) { } public void mouseExited (MouseEvent e) { } } Finding Mouse Location Inside mouseClicked the argument e of type MouseEvent can . | Chapter 11 Java AWT Part I: Mouse Events (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: introduce event driven programming show how a program can respond to mouse events (. clicks and mouse movements) demonstrate how to implement a listener interface show how mouse events can be used to build highly interactive programs Abstract Windowing Toolkit (AWT) Part of the Java distribution, but not part of the Java language itself AWT is library of classes and methods used by Java programmers that supported are by the basic Java runtime libraries Even though this chapter is labeled optional, it is not possible to be a complete Java programmer without understanding the AWT Java Events Events are occurrences outside of the program to which the program must respond (. user key press) Event managers are methods that first catch the event Listener classes send

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
24    17    1    24-11-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.