黑马程序员技术交流社区

标题: 鼠标进入事件 [打印本页]

作者: 15383016390    时间: 2015-6-26 09:25
标题: 鼠标进入事件
我给按钮添加鼠标监听器,可就是没有效果,还提示鼠标事件无效。下面是我的代码。
public class MouseEvent {
        private Frame f;
        private Button b;
        MouseEvent(){
                init();
        }
        public void init(){
                f=new Frame("myFrame");
                f.setBounds(400, 400, 600, 800);
                f.setLayout(new FlowLayout());
                f.setBackground(new Color(0,100,0));
                b=new Button("Mybutton");
                f.add(b);
                myEvent();
                f.setVisible(true);
        }
        private void myEvent(){
                f.addWindowListener(new WindowAdapter(){
                        public void windowClosing(WindowEvent e){
                                System.out.println("我关了");
                                System.exit(0);
                        }
                });
                b.addActionListener(new ActionListener(){
                        int a=0;
                        public void actionPerformed(ActionEvent e) {
                                System.out.println("Action"+a++);                               
                        }
                       
                });
                b.addMouseListener(new MouseAdapter(){
                        int c;
                        public void mouseEntered(MouseEvent e){
                                System.out.println("enter"+c++);
                        }
                });
        }

        public static void main(String[] args) {
                // TODO Auto-generated method stub
                new MouseEvent();
        }


}



作者: Huan220_欢    时间: 2015-6-26 09:25
C:\Users\Administrator\Desktop\tupian\1122.jpg

作者: Huan220_欢    时间: 2015-6-26 10:09
你的类名出错了。是关键字。改一下再运行一遍就可以了
作者: JamesLucky    时间: 2015-6-26 22:42
改一下类名
作者: zhangshuai_123    时间: 2015-7-2 11:21
要不就是没有导入功能
作者: 15383016390    时间: 2015-7-2 11:36
zhangshuai_123 发表于 2015-7-2 11:21
要不就是没有导入功能

就是类名写成了关键字。
作者: threeforPP    时间: 2015-7-4 21:26
类名错了么?我没看太懂!!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2