package result;
//鼠标事件处理,及适配器
import javax.swing.*;
import java.awt.event.*;
public class F8 {
JFrame jFrame = new JFrame("鼠标哈哈");
JTextField jTextField = new JTextField(13);
JLabel jLabel = new JLabel("请拖拽鼠标");
public F8() {
jFrame.setSize(500, 300);
jFrame.setVisible(true);
jFrame.add(jLabel, "North");
jFrame.add(jTextField, "South");
jFrame.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
jTextField.setText("鼠标进入");
}
// public void mouseExited(MouseEvent e) {
// jTextField.setText("鼠标离开");
// }
public void mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(null, "单击鼠标\t" + "次数为:" + e.getClickCount());
System.out.println("左键右键次数:" + e.getModifiers());
}
});
jFrame.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
jTextField.setText("拖拽鼠标:" + "(" + e.getX() + "," + e.getY() + ")");
}
public void mouseMoved(MouseEvent e) {
jTextField.setText("移动鼠标:" + "(" + e.getX() + "," + e.getY() + ")");
}
});
jFrame.validate();
}
public static void main(String[] args) {
new F8();
}
}