日期:2014-05-18 浏览次数:20655 次
package mkdemo;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JPanel;
public class MouseMonitor extends JPanel {
protected int _xPos
protected int _yPos;
public void tellMouseInfo(int x, int y) {
_xPos = x;
_yPos = y;
repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
StringBuffer sbuf = new StringBuffer();
sbuf.append("Mouse Location on screen: x = ");
sbuf.append(String.valueOf(_xPos));
sbuf.append(", y = ");
sbuf.append(String.valueOf(_yPos));
Rectangle rect = this.getBounds();
g.drawString(sbuf.toString(), rect.x+20, (rect.y+rect.height)/2);
}
}