当前位置: 技术问答>java相关
请问repaint()延迟问题?
来源: 互联网 发布时间:2017-03-10
本文导语: 程序片断 private void redraw() { System.out.println("redraw begin"); //... repaint(); serviceRepaints(); //... System.out.println("redraw end"); } 还有我在paint(Graphics g)里写有System.out.println("in paint"); 结果调...
程序片断
private void redraw()
{
System.out.println("redraw begin");
//...
repaint();
serviceRepaints();
//...
System.out.println("redraw end");
}
还有我在paint(Graphics g)里写有System.out.println("in paint");
结果调用redraw时在打印出来的redraw begin 和 redraw end 之间没看见in paint打印出来!
如何让repaint()立即生效?有办法吗?
private void redraw()
{
System.out.println("redraw begin");
//...
repaint();
serviceRepaints();
//...
System.out.println("redraw end");
}
还有我在paint(Graphics g)里写有System.out.println("in paint");
结果调用redraw时在打印出来的redraw begin 和 redraw end 之间没看见in paint打印出来!
如何让repaint()立即生效?有办法吗?
|
使用双缓冲
Image buffer = Image.createImage(getWidth(), getHeight());
Graphics gc = buffer.getGraphics();
//do some drawing work
public void paint(Graphics g){
g.drawImage(buffer, 0, 0, 0);
}
Image buffer = Image.createImage(getWidth(), getHeight());
Graphics gc = buffer.getGraphics();
//do some drawing work
public void paint(Graphics g){
g.drawImage(buffer, 0, 0, 0);
}
|
你使用的什么模拟器?
我想你用了serviceRepaints();就应该在返回前相应paint()的
我想你用了serviceRepaints();就应该在返回前相应paint()的