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("鼠標(biāo)進(jìn)入到該組件"+count++); } public ? void ? mouseClicked(MouseEvent ?e) { System.out.println("點(diǎn)擊動(dòng)作"+clickCount++); } }); } public ?static ?void ?main(String[] ?args) { new ?FrameDemo(); }}
1 回答

HEI_ComeOn
TA貢獻(xiàn)8條經(jīng)驗(yàn) 獲得超4個(gè)贊
因?yàn)檫@兩個(gè)值所記錄的東西不同啊 ??
count ?用來(lái)記錄鼠標(biāo)進(jìn)入該組件的次數(shù),但是進(jìn)入不一定會(huì)點(diǎn)擊啊。而 ?clickCount是用來(lái)記錄點(diǎn)擊的次數(shù)。count應(yīng)該是會(huì)大于等于clickCount的
添加回答
舉報(bào)
0/150
提交
取消