‧Mouse Entered:滑鼠進入 Component 區域中。
‧Mouse Exit:滑鼠離開 Component 區域。
‧Mouse Pressed:在 Component 區域中按下滑鼠按鍵。
‧Mouse Release:在 Component 區域中放開滑鼠按鍵。
‧Mouse Click:在 Component 區域中按下然後放開滑鼠按鍵。
可以簡單地用以下的程式碼做測試。
import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JTextPane; public class MainPanel extends JFrame { private JTextPane mainPanel = null; public MainPanel () { this.initialPanel(); this.initialJFrame(); } private void initialJFrame () { this.add(this.mainPanel); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(200, 100); this.setLocationRelativeTo(null); this.setAlwaysOnTop(true); this.setVisible(true); } private void initialPanel () { this.mainPanel = new JTextPane(); this.mainPanel.setEditable(false); this.mainPanel.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent arg0) { System.out.println("Mouse release: " + arg0.toString()); } @Override public void mousePressed(MouseEvent arg0) { System.out.println("Mouse press: " + arg0.toString()); } @Override public void mouseExited(MouseEvent arg0) { System.out.println("Mouse exit: " + arg0.toString()); } @Override public void mouseEntered(MouseEvent arg0) { System.out.println("Mouse enter: " + arg0.toString()); } @Override public void mouseClicked(MouseEvent arg0) { System.out.println("Mouse click: " + arg0.toString()); } }); } }
沒有留言:
張貼留言