Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Java Programming for absolute beginner- P16:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | JavaProgAbsBeg-07.qxd 2 25 03 8 53 AM Page 258 k 0 c c 0 2 V 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 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 depending 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 however I had to use the code list.getItem Integer e.getItem .intValue 0 a c E E s k a o k a s s 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 i ntValue method which returns an int type value of the Integer object. Then I had to take that intvalue 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 ItemEvent fields and methods. 7.8 ItemEvent Fields 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 Line - 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 Handling AdjustmentEvents The