[填空题] 本题的功能是用复选按钮来控制鼠标右键的弹出菜单是否弹出。窗口中有一个复选按钮“弹出菜单”,如果选中该复选按钮后,鼠标置于窗口上,单击鼠标右键会弹出一个菜单,单击菜单项中的选项后,后台会输出单击的菜单项,如果取消该复选按钮的选择,单击鼠标右键则不能弹出菜单。
import java. awt. * ;
import java. awt. event. * ;
class CanvasWithPopup extends Canvas
Popupmenu popup;
CanvasWithPopup(PopupMenu popup)
enableEvents(AWTEvent. MOUSE_EVENT_MASK);
this. popup=popup;
void addPopup()
add(popup);
void removePopup()
remove(popup);
protected void proeessMouseEvent(MouseEventevt)
if(popup. getParent()!=null && evt. isPopupTrigger())
popup. show(evt. getComponent(), evt. getX(), evt. getY());
super. processMouseEvent(evt);
public class java3 extends Frame implements ItemListener, ActionListener
Checkbox cb=new Checkbox("弹出菜单", false);