A menu item is only useful if it does something when selected. A menu item is just like other OpenLaszlo objects. All you need to do to make it react to an event is add an event handler to its selected event.
The code in Listing 9.4 shows an LZX application with menu items that resize a window when selected.
<canvas> <window id="win" title="Demo" width="150" height="200"/> <menubar> <menu text="Action" width="100"> <menuitem text="Minimize"> <method event="onselect"> win.setWidth(50); win.setHeight(50); </method> </menuitem> <menuitem text="Maximize"> <method event="onselect"> win.setWidth(150); win.setHeight(200); </method> </menuitem> </menu> </menubar> </canvas> |
Use this URL to compile the program in Listing 9.4.
http://localhost:8080/lps-4.0.x/app09/menuTest4.lzx
Figure 9.5 shows the result.