
Java Programming for absolute beginner- P16
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Java Programming for absolute beginner- P16 JavaProgAbsBeg-07.qxd 2/25/03 8:53 AM Page 258 258 The output for this application is shown in Figure 7.14. Within the itemState- Changed(ItemEvent) method, two string objects are built based on which event Java Programming for the Absolute Beginner occurred. The getStateChange() method determines whether the item was selected or deselected by comparing the returned value to ItemEvent.SELECTED or ItemEvent.DESELECTED. The program then obtains the value of the item depend- ing on what type of component it is. The getItem() method in the ItemEvent class returns an Object object that represents the item that triggered the event. For the Checkbox and the Choice, this works out great because the object returned is a string that can be added to the Event: string. For the List, how- ever, I had to use the code: list.getItem(((Integer)e.getItem()).intValue()) FIGURE 7.14 ItemEvents are triggered by Checkboxes, Choices, and Lists. because e.getItem() returns the Integer index of the List item that was either selected or deselected. I had to explicitly cast it to an Integer object and call its intValue() method, which returns an int type value of the Integer object. Then I had to take that int value and pass it into list.getItem(int) so that I could get the String value of the List item. Table 7.8 lists some of the more common Ite- mEvent fields and methods. TA B L E 7 . 8 I TEM E VENT F I E L D S AND METHODS Field or Method Description int DESELECTED Signifies that the ItemEvent occurred because an item was deselected. int SELECTED Signifies that the ItemEvent occurred because an item was selected. int getStateChange() Returns a value, either ItemEvent.DESELECTED or ItemEvent.SELECTED depending on what type of state change is associated with this ItemEvent. Object getItem() Returns an Object that represents the item whose state changed. TEAM LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-07.qxd 2/25/03 8:53 AM Page 259 259 Handling AdjustmentEvents Chapter 7 The AdjustmentListener interface listens for AdjustmentEvents, which are trig- gered by objects that are adjustable, such as the Scrollbar component. Adjust- mentListener has only one method, adjustmentValueChanged(AdjustmentEvent), which is invoked when the value of an adjustable object is changed, as you can probably guess from the name of the method. The AdjustmentTest application tests this: Advanced GUI: Layout Managers and Event Handling /* * AdjustmentTest * Demonstrates the AdjustmentListener Interface on a scroll bar */ import java.awt.*; import java.awt.event.*; public class AdjustmentTest extends GUIFrame implements AdjustmentListener { ...
Tìm kiếm theo từ khóa liên quan:
Nhập môn lập trình lập trình website lập trình ngôn ngữ html giáo trình php lập trình C++Tài liệu có liên quan:
-
Đề cương chi tiết học phần Cấu trúc dữ liệu và giải thuật (Data structures and algorithms)
10 trang 357 0 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 204 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 188 0 0 -
Giáo trình nhập môn lập trình - Phần 22
48 trang 143 0 0 -
[Thảo luận] Học PHP như thế nào khi bạn chưa biết gì về lập trình?
5 trang 137 0 0 -
8 trang 99 0 0
-
Bài giảng Nhập môn lập trình - Chương 12: Quản lý bộ nhớ
23 trang 69 0 0 -
Giáo trình Lập trình Website (Nghề Tin học ứng dụng - Trình độ Cao đẳng) - CĐ GTVT Trung ương I
156 trang 62 2 0 -
Báo cáo đồ án môn học II: Thiết kế website bán đồng hồ
25 trang 55 0 0 -
42 trang 53 0 0
-
Tạo mạng xã hội với PHP - part 43
10 trang 46 0 0 -
4 trang 43 0 0
-
Bài giảng Nhập môn lập trình: Bài 2 - Thuật toán
32 trang 42 0 0 -
Nhập môn lập trình (Đặng Bình Phương) - Các khái niệm cơ bản về hệ điều hành
17 trang 39 0 0 -
MỘT SỐ KHÁI NIỆM CƠ BẢN CỦA NGÔN NGỮ C
49 trang 38 0 0 -
Một số giải pháp lập trình ASP.NET 2.0
82 trang 38 0 0 -
LẬP TRÌNH C ++ QUẢN LÝ NHÀ TRỌ
12 trang 38 0 0 -
Câu hỏi bài tập nhập môn lập trình
11 trang 37 0 0 -
CÁC KHÁI NIỆM CƠ BẢN VỀ LẬP TRÌNH
21 trang 36 0 0 -
142 trang 35 0 0