TAILIEUCHUNG - Java By Example PHẦN 6

menu, Java tạo ra một sự kiện mà bạn có thể chụp trong hành động () phương pháp. Trong trường hợp của một trình đơn lựa chọn, tham số đầu tiên hành động () là một ví dụ menu, và các tham số thứ hai là các văn bản của các mục menu được chọn. | menu Java generates an event that you can capture in the action method. In the case of a choice menu action s first parameter is the menu instance and the second parameter is the text of the selected menu item. By comparing the text to the items you added to the menu you can determine which menu item the user chose. The ChoiceApplet applet whose source code is shown in Listing demonstrates creating and responding to choice menus in an applet. Listing is the applet s HTML document. When you run the applet under Appletviewer you see the window shown in Figure . The text in the window is displayed using the currently selected color in the choice menu. To change the text color just select a new menu item. Figure ChoiceApplet displays text in the color selected from its choice menu. Listing Using Menus in an Applet. import . import . public class ChoiceApplet extends Applet Choice menu Color color public void init Choice menu new Choice Black Red Green Blue add menu color public void paint Graphics g Font font new Font TimesRoman 24 int height font color This text is drawn in 32 75 the color selected from 32 75 height the above choice menu. 32 75 2 height public boolean action Event evt Object arg if instanceof Choice HandleMenu arg return true protected void HandleMenu Object item if item Black color else if item Red color else if item Green color else color repaint

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.