| 我给按钮添加鼠标监听器,可就是没有效果,还提示鼠标事件无效。下面是我的代码。 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();
 }
 
 
 }
 
 
 
 |