关于Java中的(Graphics g, Graphics2D)存在问题

huangapple go评论73阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年4月9日 08:59:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/61112349.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定