资 源 简 介
Java实现窗体右键菜单,简约易操作的窗体菜单,这是一个相当易懂的制作实例。
super( "右键弹出菜单" ); //调用父类构造函数
ChangeColorAction action = new ChangeColorAction(); //菜单项事件处理
String[] str = {"Blue","Pink","Yellow","Red","Orange"}; //菜单项名称
ButtonGroup colorGroup=new ButtonGroup(); //实例化按钮组
popupMenu=new JPopupMenu(); //实例化弹出菜单
items=new JRadioButtonMenuItem[5]; //初始化数组
for (int i=0;i items[i]=new JRadioButtonMenuItem(str[i]); //实例化菜单项
popupMenu.add(items[i]); //增加菜单项到菜单上
colorGroup.add(items[i]); //增加菜单项到按钮组
items[i].addActionListener(action); //菜单项事件处理
}
addMouseListener(new MouseAdapter(){ //窗口的鼠标事件处理
public void mousePressed( MouseEvent event ) { //点击鼠标
triggerEvent(event); //调用triggerEvent方法处理事件