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(); }}
1 回答
HEI_ComeOn
TA贡献8条经验 获得超4个赞
因为这两个值所记录的东西不同啊
count 用来记录鼠标进入该组件的次数,但是进入不一定会点击啊。而 clickCount是用来记录点击的次数。count应该是会大于等于clickCount的
添加回答
举报
0/150
提交
取消