【发布时间】:2012-07-25 19:05:23
【问题描述】:
Thread线程运行时,(点击记录后)只显示线程启动时鼠标所在的位置?我怎样才能让它不断更新,即使我在框架周围移动鼠标也能显示鼠标的位置?
@Override public void actionPerformed(ActionEvent e)
{
thread = new Thread(this);
if(e.getSource() == record)
{
thread.start();
System.out.println("record");
}
if(e.getSource() == stopRecording)
{
setVisible(false);
System.out.println("stop recording");
}
}
@Override public void run()
{
setTitle("979");
setSize(screen.width, screen.height);
addMouseListener(this);
setLocationRelativeTo(null);
setLayout(transFlo);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(stopRecording);
setOpacity(0.50f);
setVisible(true);
while(true)
{
repaint();
}
}
@Override public void paint(Graphics g)
{
g.drawString(mousePOS + x + space + y, 250, 250);
}
【问题讨论】:
-
请阅读docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html。
mousePOS变量是如何更新的? -
x 和 y 改变 mousePOS 不
-
当鼠标移动时它们会改变
-
对不起,错过了鼠标监听器:P
-
我建议您的线程使编辑饱和,从而无法响应绘画请求
标签: java swing mouseevent mouseclick-event mouse-coordinates