giáo trình Java By Example phần 2

Tham khảo tài liệu 'giáo trình java by example phần 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 25 Mouse and Keyboard Events CONTENTS The Event Object The Mouse o Handling Mouse Clicks o Example Using Mouse Clicks in an Applet o Handling Mouse Movement o Example Responding to Mouse Movement in an Applet The Keyboard o Responding to Key Presses o Predefined Key Constants o Key Modifiers o Example Using Key Presses in an Applet J Handling Events Directly o Example Overriding handleEvent in an Applet Summary Review Questions Review Exercises Up until now your applets have responded to events generated by Java components like buttons text fields and list boxes. You ve yet to examine how to respond to events generated by the most basic of a computer s controls the mouse and the keyboard. Because virtually every computer has these important hardware controls you can confidently take advantage of them in your applets to collect various types of input. In this chapter you learn the secrets of mouse and keyboard handling in Java applets. The Event Object In order to understand how to respond to various types of events you need to know more about Java s Event class an object of which is passed to any event-handling method. When you want to respond to a Java button control for example you override the action method whose first argument is an Event object. You then examine the target field of the Event object to determine whether it was the http button control that generated the event. The Event class however defines many constants and data fields that provide information about the event represented by the object. First the Event class defines constants for all of the events to which an event-handling method can respond. In this chapter you ll learn about some of these constants which include MOUSE_DOWN MOUSE_UP and KEY_PRESS. The class also defines constants for special keys such as fl PGUP PGDN HOME and so on. Finally the Event class defines the data fields shown in Table . How you use these data fields depends on the type of event .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
46    112    4    29-04-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.