当前位置: 技术问答>java相关
menuitem 的mouseclicked事件为什么不响应?
来源: 互联网 发布时间:2015-05-08
本文导语: 已经加入监听了啊,看一下部分程序,点击‘文件’可以弹出消息框,点击‘打开’,就不能,为什么? jMenu1.setText("文件"); jMenu1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent...
已经加入监听了啊,看一下部分程序,点击‘文件’可以弹出消息框,点击‘打开’,就不能,为什么?
jMenu1.setText("文件");
jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jMenu1_mouseClicked(e);
}
});
jMenuItem1.setText("打开");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem1_actionPerformed(e);
}
……………………
void jMenu1_mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(null, "打开", "打开" ,JOptionPane.INFORMATION_MESSAGE );
}
void jMenuItem1_mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(null, "打开", "打开" ,JOptionPane.INFORMATION_MESSAGE );}
jMenu1.setText("文件");
jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jMenu1_mouseClicked(e);
}
});
jMenuItem1.setText("打开");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem1_actionPerformed(e);
}
……………………
void jMenu1_mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(null, "打开", "打开" ,JOptionPane.INFORMATION_MESSAGE );
}
void jMenuItem1_mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(null, "打开", "打开" ,JOptionPane.INFORMATION_MESSAGE );}
|
写错了个参数:
void jMenuItem1_mouseClicked(ActionEvent e) {
JOptionPane.showMessageDialog(null, "打开", "打开" ,JOptionPane.INFORMATION_MESSAGE );}
void jMenuItem1_mouseClicked(ActionEvent e) {
JOptionPane.showMessageDialog(null, "打开", "打开" ,JOptionPane.INFORMATION_MESSAGE );}