tailieunhanh - Object Oriented Programming - Lesson 12.2: GUI and Event Programming (cont.)

Object Oriented Programming - Lesson : GUI and Event Programming (cont.) create menus inside an AWT application, process action when choosing a menu item, create shortcuts for menu items, create a popup menu when right-clicking on any AWT components. | LESSON . GUI and Event Programming (cont.) Trinh Thanh TRUNG (MSc) trungtt@ 1 Objectives • After this lesson, students (learners) can: Create menus inside an AWT application Process action when choosing a menu item Create shortcuts for menu items Create a popup menu when right-clicking on any AWT components – Understand Swing’s advanced features compared to AWT’s – Write Swing application – – – – 2 Content IV. AWT Menu V. Programming GUI with Swing 3 IV. AWT menu Menu • Class hierarchy: MenuComponent MenuBar MenuItem CheckBoxMenuItem Menu PopupMenu 4 . Steps to add menus to a Frame • 1. Create a MenuBar MenuBar mb = new MenuBar(); • 2. Create a Menu Menu m = new Menu("File"); • 3. Add MenuItem to the menu (new MenuItem("Open")); (new CheckboxMenuItem("Type here")); • 4. Add the menu to the Menubar (m); • 5. add the MenuBar to the Frame by calling the setMenuBar() .