[英]Draw graphics without deleting them when using repaint()
I have a draw method and I want the drawLine to remain on the screen after I call repaint(). 我有一个draw方法,我希望drawLine在调用repaint()后保留在屏幕上。 The fillOval will be moving, that is ok. fillOval将会移动,没关系。 But i want the drawLine to be redraw just on another position without deleting it. 但我希望drawLine只是在另一个位置重绘而不删除它。
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.RED);
g.drawLine(x, y, x+10, y+10);
g.setColor(Color.BLACK);
g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
}
In the repaint request, you must specify the coordinates and dimensions of the "dirty area" by using one of the following methods: 在重绘请求中,您必须使用以下方法之一指定“脏区”的坐标和尺寸:
Note that you'll want to override paintComponent
, not paint
when performing custom painting. 请注意,您将要覆盖paintComponent
,而不是在执行自定义paint
时绘制。
You can store the x
and y
of every line in a List
. 您可以将每行的x
和y
存储在List
。 On each repaint()
, you just redraw all the lines present in the List
在每个repaint()
,您只需重绘List
所有行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.