private  int  count=1; private  int  clickCount=1;为什么又两次定义?

import  java.awt.*;

import  java.awt.event.*;

class  FrameDemo

{

private  Frame  f;

private   Button  but;

FrameDemo()

{

init();

}

public   void  init()

{

f=new  Frame("my  frame");

f.setBounds(300,100,600,500);

f.setLayout(new   FlowLayout());

but=new  Button("my  button");

f.add(but);

myEvent();

f.setVisible(true);

}

private   void   myEvent()

{

f.addWindowListener(new  WindowAdapter()

{

public   void   windowClosing(WindowEvent   e)

{

System. exit(0);

}

});

but.addActionListener(new  ActionListener()

{

public   void   actionPerformed(ActionEvent  e)

{

System.out.println("action  ok");

}

});

but.addMouseListener(new  MouseAdapter()

{

private  int  count=1;

private  int  clickCount=1;

public   void   mouseEntered(MouseEvent  e)

{

System.out.println("鼠标进入到该组件"+count++);

}

public   void   mouseClicked(MouseEvent  e)

{

System.out.println("点击动作"+clickCount++);

}

});

}

public  static  void  main(String[]  args)

{

new  FrameDemo();

}

}


qq_丘比特_0
浏览 2103回答 1
1回答

HEI_ComeOn

因为这两个值所记录的东西不同啊   count  用来记录鼠标进入该组件的次数,但是进入不一定会点击啊。而  clickCount是用来记录点击的次数。count应该是会大于等于clickCount的
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java