Java操作應(yīng)用——捕獲鼠標(biāo)動(dòng)作
實(shí)現(xiàn)了MouseMotionListner接口后,便可以捕獲鼠標(biāo)事件了。 當(dāng)鼠標(biāo)進(jìn)入到某個(gè)特定區(qū)域時(shí)便會(huì)觸發(fā)MouseMoved事件,你便能捕獲到這個(gè)移動(dòng)的動(dòng)作了。通過(guò)一個(gè)例子來(lái)看下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import java.awt.event.*; import javax.swing.*; public class MouseCaptureDemo extends JFrame implements MouseMotionListener { public JLabel mouseHoverStatus; public static void main(String args[]) { new MouseCaptureDemo(); } MouseCaptureDemo() { setSize( 500 , 500 ); setTitle( "Frame displaying Coordinates of Mouse Motion" ); mouseHoverStatus = new JLabel( "No Mouse Hover Detected." , JLabel.CENTER); add(mouseHoverStatus); addMouseMotionListener( this ); setVisible( true ); } public void mouseMoved(MouseEvent e) { mouseHoverStatus.setText( "Mouse Cursor Coordinates => X:" +e.getX()+ " | Y:" +e.getY()); } public void mouseDragged(MouseEvent e) {} } FileOutputStream Vs. FileWriter |
點(diǎn)擊加載更多評(píng)論>>