📄 app16_9.java
字号:
// app16_9, 以MouseMotionListener接口处理MouseEvent事件
import java.awt.*;
import java.awt.event.*;
public class app16_9 extends Frame implements MouseMotionListener
{
static app16_9 frm=new app16_9();
static Label labx=new Label();
static Label laby=new Label();
static Label lab=new Label();
public static void main(String agrs[])
{
frm.setLayout(null);
frm.addMouseMotionListener(frm); // 设置frm为事件本身的聆听者
labx.setBounds(40,40,40,20);
laby.setBounds(100,40,40,20);
lab.setBounds(40,80,100,40);
frm.setSize(200,150);
frm.setTitle("Mouse Event");
frm.add(labx);
frm.add(laby);
frm.add(lab);
frm.setVisible(true);
}
public void mouseMoved(MouseEvent e) // 当鼠标移开时
{
labx.setText("x="+e.getX()); // 显示X坐标
laby.setText("y="+e.getY()); // 显示Y坐标
lab.setText("Mouse Moved!!"); // 显示"Mouse Moved!!"字符串
}
public void mouseDragged(MouseEvent e) // 当鼠标拖拽时
{ labx.setText("x="+e.getX()); // 显示X坐标
laby.setText("y="+e.getY()); // 显示Y坐标
lab.setText("Mouse Dragged!!"); // 显示"Mouse Dragged!!"字符串
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -