import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/**
* <p>Title: 鼠標檢測</p>
* <p>Description: 在applet使用鼠標事件,檢測鼠標的動作。</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Filename: MouseAd.java</p>
* @version 1.0
*/
public class MouseAd extends Applet{
int x=0,y=0;
int width,height;
/**
*<br>方法說明:Applet初始化,添加了一個鼠標監聽對象。
*<br>輸入參數:
*<br>返回類型:
*/
public void init() {
addMouseListener(new Mouse());
} //end init
/**
*<br>類說明:繼承MouseAdapter類,實現鼠標點擊監聽。
*<br>功能描述:獲取鼠標在Applet上點擊的位置
*/
class Mouse extends MouseAdapter {
public void mousePressed(MouseEvent e) {
x=e.getX();
y=e.getY();
width = size().width;
height = size().height;
repaint();
} //end mousePressed
} //end Mouse
/**
*<br>方法說明:繪制Applet屏幕,根據鼠標位置繪制坐標
*<br>輸入參數:
*<br>返回類型:
*/
public void paint(Graphics g) {
g.drawString("x="+x+" y="+y,10,20);
g.drawLine(x,0,x,height);
g.drawLine(0,y,width,y);
} //end paint
} // end MouseAd