swing中左右中鼠标事件

addMouseListener(new MouseListener(){   
    
                        public void mouseClicked(MouseEvent e) {   
                                //      鼠标按键在组件上单击(按下并释放)时调用   
                                label.setText("鼠标在panel容器上单击(按下并释放)");   
                        }   
    
                        public void mouseEntered(MouseEvent e) {   
                                //      鼠标进入到组件上时调用   
                                label.setText("鼠标进入panel容器");   
                        }   
    
                        public void mouseExited(MouseEvent e) {   
                                //      鼠标离开组件时调用   
                                label.setText("鼠标离开panel容器");   
                        }   
    
                        public void mousePressed(MouseEvent e) {   
                                //      鼠标按键在组件上按下时调用   
                                if(e.getClickCount()==2){   
                                        JOptionPane.showMessageDialog(null,"鼠标在panel容器上双击!");   
                                }   
                            if(e.getButton()==e.BUTTON3){   
                                        label.setText("鼠标右键在panel容器上按下");   
                                }   
                                if(e.getButton()==e.BUTTON1){   
                                        label.setText("鼠标左键在panel容器上按下");   
                                }   
                                if(e.getButton()==e.BUTTON2){   
                                        label.setText("鼠标中键在panel容器上按下");   
                                }   
                        }   
    

你可能感兴趣的:(swing)