Đang chuẩn bị liên kết để tải về tài liệu:
Lecture note Java methods A & AB: Object-oriented programming and data structures: Chapter 17 - Maria Litvin, Gary Litvin

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

Chapter 17 - Mouse, keyboard, sounds, and images. This is essentially a “learning by doing” chapter. Not much theory here. This chapter also introduces bit-wise logical operators in the context of identifying the status of keyboard modifier keys (Alt, Shift, Ctrl). | Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Mouse, Keyboard, Sounds, and Images 17- This is essentially a “learning by doing” chapter. Not much theory here. Objectives: Learn how to handle mouse and keyboard events in Java. Implement a simple drawing editor application. Learn the basics of playing sounds and displaying images in applets and applications. 17- This chapter also introduces bit-wise logical operators in the context of identifying the status of keyboard modifier keys (Alt, Shift, Ctrl). Mouse Events Mouse events are captured by an object which is a MouseListener and possibly a MouseMotionListener. A mouse listener is often attached to a JPanel component. It is not uncommon for a panel to serve as its own mouse listener: public MyPanel() { . addMouseListener(this); addMouseMotionListener(this); // optional 17- A mouse | Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Mouse, Keyboard, Sounds, and Images 17- This is essentially a “learning by doing” chapter. Not much theory here. Objectives: Learn how to handle mouse and keyboard events in Java. Implement a simple drawing editor application. Learn the basics of playing sounds and displaying images in applets and applications. 17- This chapter also introduces bit-wise logical operators in the context of identifying the status of keyboard modifier keys (Alt, Shift, Ctrl). Mouse Events Mouse events are captured by an object which is a MouseListener and possibly a MouseMotionListener. A mouse listener is often attached to a JPanel component. It is not uncommon for a panel to serve as its own mouse listener: public MyPanel() { . addMouseListener(this); addMouseMotionListener(this); // optional 17- A mouse listener can be implemented as an inner class or even an inline class, as follows: public class MyPanel extends JPanel { public MyPanel() // constructor { . addMouseListener(new MouseAdapter() // inline class { public void mouseClicked(MouseEvent e) { . // process click at e.getX(), e.getY() } } ); . } } Mouse Events (cont’d) The MouseListener interface defines five methods: void mousePressed (MouseEvent e) void mouseReleased (MouseEvent e) void mouseClicked (MouseEvent e) void mouseEntered (MouseEvent e) void mouseExited (MouseEvent e) One click and release causes several calls. Using only mouseReleased is usually a safe bet. Called when the mouse cursor enters/exits component’s visible area 17- mouseClicked checks that the button was pressed and released in the same place, which may result in missed clicks. Mouse Events (cont’d) Mouse listener methods receive a MouseEvent object as a parameter. A mouse event can provide the coordinates of the event and other information: .

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