创建菜单选项 JRadioButtonMenuItem
这是部分代码:
JMenu myMenu = new JMenu("Color");
JMenu myMenu2 = new JMenu("Color");
myMenu.add(myMenu2);
myGroup = new ButtonGroup();
JRadioButtonMenuItem myItem = new JRadioButtonMenuItem("Red");
myItem.setSelected(true);
myGroup.add(myItem);
myMenu2.add(myItem);
myItem.setActionCommand("Red");
myItem = new JRadioButtonMenuItem("Green");
myItem.setActionCommand("Green");
myGroup.add(myItem);
myMenu2.add(myItem);
myItem = new JRadioButtonMenuItem("Blue");
myItem.setActionCommand("Blue");
myGroup.add(myItem);
myMenu2.add(myItem);