英文:
Problem with (Graphics g, Graphics2D) on Java
问题
I cant keep the past line i draw with "g2d.drawLine(w, x, y, z);",
I call "repaint()" to update the Jpanel and it just draws a new Line, I need to keep the past Lines i have draw.
What it should do:
enter image description here
What id do:
enter image description here
英文:
I cant keep the past line i draw with "g2d.drawLine(w, x, y, z);",
I call "repaint()" to update the Jpanel and it just draws a new Line, I need to keep the past Lines i have draw.
What it should do: enter image description here
What id do:enter image description here
答案1
得分: 1
你可以使用一个Point对象的ArrayList,每次进行任何计算时,只需将终点保存到其中。每次面板重绘时,只需按照添加顺序在你的ArrayList中的所有点之间绘制线条。
英文:
You could use an ArrayList of Point objects, every time you do whatever calculation you're doing, just save the end point to it. Every time the panel repaints, just draw lines between all of the points in your ArrayList, in the same order they were added.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论