Java实现右键弹出菜单例子Java认证考试
文章作者 100test 发表时间 2011:03:01 01:10:41
来源 100Test.Com百考试题网
import java.awt.*.
import java.awt.event.*.
import javax.swing.*.
//左键弹出菜单
public class JPopMenuDemo extends JFrame {
JRadioButtonMenuItem items[]. //菜单项
Color[] colors={Color.blue,Color.pink,Color.yellow,Color.red,Color.orange}. //颜色数组
JPopupMenu popupMenu. //弹出菜单
public JPopMenuDemo()
{
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