TAILIEUCHUNG - giáo trình Java By Example phần 3

Tham khảo tài liệu 'giáo trình java by example phần 3', 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ả | MenuBar menuBar new MenuBar As you can see the MenuBar constructor requires no arguments. After you ve created the MenuBar object you have to tell Java to associate the menu bar with the frame window. You do this by calling the window s setMenuBar method setMenuBar menuBar At this point you have an empty menu bar associated with the window. In the next steps you add menus to the menu bar. Adding Menus to a Menu Bar A menu bar is the horizontal area near the top of a window that contains the names of the menus contained in the menu bar. After creating and setting the MenuBar object you have the menu bar but it contains no menus. To add these menus you first create objects of the Menu class for each menu you want in the menu bar like this Menu fileMenu new Menu File Menu editMenu new Menu Edit Menu optionMenu new Menu Options The Menu class s constructor takes a single argument which is the string that ll appear as the menu s name on the menu bar. The example lines above create three menus for the menu bar. After creating the Menu objects you have to add them to the menu bar which you do by calling the MenuBar object s add method like this fileMenu editMenu optionMenu After Java executes the above three lines you have a menu bar with three menus as shown in Figure . Note however that at this point the menus contain no commands. If you were to click on the menu http names no pop-up menus would appear. Figure This window s menu bar contains three empty menus. Adding Menu Items to Menus You may have empty menus at this point but you re about to remedy that problem. To add items to your menus you first create objects of the Menuitem or CheckboxMenuitem classes for each menu item you need. To add items to the Options menus you made previously you might use Java code something like this Menuitem optionl new Menuitem Menuitem option2 new Menuitem Option 1 Option 2 Menuitem options new Menuitem Option 3 The .

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.