我在画布上画了一些多边形,并想在画的多边形上画一些线。如果我在画线后画线,画的多边形会覆盖线,但如果我先画线,线会完全消失。代码在 Scala 中,但我认为所有相关代码都来自 Java 库。
编辑我已经扩展了代码以响应 Rex Kerr 的评论
package rStrat
package rSw
package mapCanv
import swing._
import java.awt.geom._
import java.awt.Polygon
abstract class MapCanv [T <: TypesD](val mArea: GeomBase[T]#MapArea) extends Panel
{
type VHexT <: VisHex
val vHexs: Vec[VisHex] = mArea.mHexs.map(i => newVHexT(i))
def newVHexT(mHex: GeomBase[T]#MapArea#MapHex): VHexT
val line: Line2D.Double = new Line2D.Double(0,0, 350, 350)
override def paintComponent (gr2d: Graphics2D)
{
super.paintComponent (gr2d)
vHexs.foreach(i => i.paint(gr2d))
gr2d.draw(line)
}
abstract class VisHex (val mHex: GeomBase[T]#MapArea#MapHex) extends Polygon with PaintTr
{
mHex.verts.foreach(i => addPoint(i.x.toInt, i.y.toInt))
}
trait PaintTr
{
def paint(gr2d: Graphics2D): Unit
}
}
package rStrat //separate file
package rSw
package mapCanv
import swing._
//import java.awt._
abstract class MapCanvStd[T <: TypesStd](mArea: GeomBase[T]#MapArea) extends MapCanv[T](mArea)
{
type VHexT = VisHexStd
override def newVHexT(mHex: GeomBase[T]#MapArea#MapHex) = new VisHexStd(mHex)
class VisHexStd(mHex: GeomBase[T]#MapArea#MapHex) extends VisHex(mHex)
{
override def paint(gr2d: Graphics2D): Unit =
{
gr2d.setPaint(terrToCol(mHex.hex.terr))
gr2d.fill(this)
}
}
}