您好,我想知道如何获取鼠标在方法之外的位置 鼠标点击我需要在有人点击的地方画一个点。.这是我现在使用的代码。有人可以帮助我吗?
Dot punt = new Dot();
public void paintComponent(Graphics g) {
super.paintComponent(g);
punt.setDot(g, getX(), getY(), 5);
repaint();
}
@Override
public void mouseClicked(MouseEvent m) {
// TODO Auto-generated method stub
gebeurtenisverslag.setText(
m.getClickCount() + " keer geklikt op " + m.getX() + "," + m.getY());
}
为鼠标单击修改的类设置一个变量。
private int X;
private int Y;
@Override
public void mouseClicked(MouseEvent m) {
gebeurtenisverslag.setText(
m.getClickCount() + " keer geklikt op " + m.getX() + "," + m.getY());
X = m.getX();
Y = m.getY();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Probably want to add logic here to verify X & Y have been set
punt.setDot(g, X, Y, 5);
repaint();
}