giáo trình Java By Example phần 2
Số trang: 42
Loại file: pdf
Dung lượng: 100.15 KB
Lượt xem: 14
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
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ả
Nội dung trích xuất từ tài liệu:
giáo trình Java By Example phần 2Chapter 25Mouse and Keyboard Events CONTENTS The Event Object q The Mouse q Handling Mouse Clicks r Example: Using Mouse Clicks in an Applet r Handling Mouse Movement r Example: Responding to Mouse Movement in an Applet r The Keyboard q Responding to Key Presses r Predefined Key Constants r Key Modifiers r Example: Using Key Presses in an Applet r Handling Events Directly q Example: Overriding handleEvent() in an Applet r Summary q Review Questions q Review Exercises qUp until now, your applets have responded to events generated by Java components like buttons, textfields, and list boxes. Youve yet to examine how to respond to events generated by the most basic of acomputers controls, the mouse and the keyboard. Because virtually every computer has these importanthardware controls, you can confidently take advantage of them in your applets to collect various types ofinput. In this chapter, you learn the secrets of mouse and keyboard handling in Java applets.The Event ObjectIn order to understand how to respond to various types of events, you need to know more about JavasEvent class, an object of which is passed to any event-handling method. When you want to respond to aJava button control, for example, you override the action() method, whose first argument is anEvent object. You then examine the target field of the Event object to determine whether it was the http://www.ngohaianh.infobutton control that generated the event. The Event class, however, defines many constants and datafields 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 canrespond. In this chapter, youll 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 f1, PGUP,PGDN, HOME, and so on. Finally, the Event class defines the data fields shown in Table 25.1. How youuse these data fields depends on the type of event represented by the Event object. Table 25.1 Data Fields of the Event Class. Field Description Event-specific information. With a button event, for Object arg example, this field is the buttons label. int clickCount The click count for mouse events. A value of 1 means a single click, and 2 means a double-click. The events type, such as MOUSE_DOWN, MOUSE_MOVE, int id KEY_PRESS, etc. The key for a key-related event. For a KEY_PRESS event, int key for example, this would be the key that was pressed. The key modifiers, including the shift and control keys. The int modifiers Event class defines constants such as SHIFT_MASK and CTRL_MASK. The type of object-such as Button, TextField, and so on-that Object target generated the event. The events time stamp. long when The X coordinate associated with the event, usually used int x with mouse events to indicate the mouses position at the time of the event. The Y coordinate associated with the event, usually used int y with mouse events to indicate the mouses position at the time of the event.The MouseMost people use their computers mouse darn near as much as its keyboard. I can vouch for this fromfirst-hand experience, because my only bout with RSI (repetitive strain injury) came not from typingfuriously all day, but from maneuvering my mouse to mark paragraphs, highlight words, click buttons,make list selections, bring up menus, and any number of other mousely tasks. Im not looking for yoursympathy, though. My point is that the mouse is one of the most important input devices attached to yourcomputer. To write complete applets, youre going to have to master responding to mouse events in yourJava programs. ...
Nội dung trích xuất từ tài liệu:
giáo trình Java By Example phần 2Chapter 25Mouse and Keyboard Events CONTENTS The Event Object q The Mouse q Handling Mouse Clicks r Example: Using Mouse Clicks in an Applet r Handling Mouse Movement r Example: Responding to Mouse Movement in an Applet r The Keyboard q Responding to Key Presses r Predefined Key Constants r Key Modifiers r Example: Using Key Presses in an Applet r Handling Events Directly q Example: Overriding handleEvent() in an Applet r Summary q Review Questions q Review Exercises qUp until now, your applets have responded to events generated by Java components like buttons, textfields, and list boxes. Youve yet to examine how to respond to events generated by the most basic of acomputers controls, the mouse and the keyboard. Because virtually every computer has these importanthardware controls, you can confidently take advantage of them in your applets to collect various types ofinput. In this chapter, you learn the secrets of mouse and keyboard handling in Java applets.The Event ObjectIn order to understand how to respond to various types of events, you need to know more about JavasEvent class, an object of which is passed to any event-handling method. When you want to respond to aJava button control, for example, you override the action() method, whose first argument is anEvent object. You then examine the target field of the Event object to determine whether it was the http://www.ngohaianh.infobutton control that generated the event. The Event class, however, defines many constants and datafields 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 canrespond. In this chapter, youll 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 f1, PGUP,PGDN, HOME, and so on. Finally, the Event class defines the data fields shown in Table 25.1. How youuse these data fields depends on the type of event represented by the Event object. Table 25.1 Data Fields of the Event Class. Field Description Event-specific information. With a button event, for Object arg example, this field is the buttons label. int clickCount The click count for mouse events. A value of 1 means a single click, and 2 means a double-click. The events type, such as MOUSE_DOWN, MOUSE_MOVE, int id KEY_PRESS, etc. The key for a key-related event. For a KEY_PRESS event, int key for example, this would be the key that was pressed. The key modifiers, including the shift and control keys. The int modifiers Event class defines constants such as SHIFT_MASK and CTRL_MASK. The type of object-such as Button, TextField, and so on-that Object target generated the event. The events time stamp. long when The X coordinate associated with the event, usually used int x with mouse events to indicate the mouses position at the time of the event. The Y coordinate associated with the event, usually used int y with mouse events to indicate the mouses position at the time of the event.The MouseMost people use their computers mouse darn near as much as its keyboard. I can vouch for this fromfirst-hand experience, because my only bout with RSI (repetitive strain injury) came not from typingfuriously all day, but from maneuvering my mouse to mark paragraphs, highlight words, click buttons,make list selections, bring up menus, and any number of other mousely tasks. Im not looking for yoursympathy, though. My point is that the mouse is one of the most important input devices attached to yourcomputer. To write complete applets, youre going to have to master responding to mouse events in yourJava programs. ...
Tìm kiếm theo từ khóa liên quan:
lập trình Java tin học ứng dụng lập trình windows lập trình C# mẹo hay cho tin học thủ thuật windowsTài liệu liên quan:
-
Tài liệu bồi dưỡng giáo viên sử dụng SGK Tin học 10 Cánh diều (Định hướng Tin học ứng dụng)
61 trang 249 0 0 -
101 trang 202 1 0
-
Cách gỡ bỏ hoàn toàn các add on trên Firefox
7 trang 191 0 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 188 0 0 -
20 trang 185 0 0
-
Giáo trình Mạng máy tính (Nghề: Tin học ứng dụng - Trung cấp) - Trường Cao đẳng Cộng đồng Đồng Tháp
189 trang 166 0 0 -
bảo mật mạng các phương thức giả mạo địa chỉ IP fake IP
13 trang 161 0 0 -
Bài giảng Tin học ứng dụng: Kiểm định trung bình - Trường ĐH Y dược Huế
25 trang 152 0 0 -
Giáo trình Tin học ứng dụng: Phần 1 - Trường ĐH Tài nguyên và Môi trường Hà Nội
125 trang 151 0 0 -
175 trang 130 0 0