如何用Netbeans构建GUI程序
1个回答
2017-10-14
展开全部
JMenuItemadd(JMenuItemmenuItem)将指定菜单项添加到此菜单的末尾。JMenuItemadd(Strings)创建具有指定文本的菜单项,并将其添加到此菜单的末尾。//whereinstancevariablesaredeclared:JPopupMenupopup;//wheretheGUIisconstructed://Createthepopupmenu.popup=newJPopupMenu();menuItem=newJMenuItem("Apopupmenuitem");menuItem.addActionListener(this);popup.add(menuItem);menuItem=newJMenuItem("Anotherpopupmenuitem");menuItem.addActionListener(this);popup.add(menuItem);//Addlistenertocomponentsthatcanbringuppopupmenus.MouseListenerpopupListener=newPopupListener();output.addMouseListener(popupListener);menuBar.addMouseListener(popupListener);classPopupListenerextendsMouseAdapter{publicvoidmousePressed(MouseEvente){maybeShowPopup(e);}publicvoidmouseReleased(MouseEvente){maybeShowPopup(e);}privatevoidmaybeShowPopup(MouseEvente){if(e.isPopupTrigger()){popup.show(e.getComponent(),e.getX(),e.getY());}}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询