Java 鼠标监听器

2025-01-07 08:46:24
推荐回答(2个)
回答1:

JMenuItem againItem = startFile.add("再玩一次");//建立子菜单
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");

againItem.addActionListener(new ActionHandler());//建立鼠标监听器

}
}

class ActionHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}

或者:

JMenuItem againItem = startFile.add("再玩一次");//建立子菜单
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");

againItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}
);//建立鼠标监听器

}
}

回答2:

rtearteratetrtretfgf tgreghehthrssrrth