?? 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); // 設(shè)置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) // 當(dāng)鼠標(biāo)移開時(shí)
{
labx.setText("x="+e.getX()); // 顯示X坐標(biāo)
laby.setText("y="+e.getY()); // 顯示Y坐標(biāo)
lab.setText("Mouse Moved!!"); // 顯示"Mouse Moved!!"字符串
}
public void mouseDragged(MouseEvent e) // 當(dāng)鼠標(biāo)拖拽時(shí)
{ labx.setText("x="+e.getX()); // 顯示X坐標(biāo)
laby.setText("y="+e.getY()); // 顯示Y坐標(biāo)
lab.setText("Mouse Dragged!!"); // 顯示"Mouse Dragged!!"字符串
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -