我已经从尝试通过 Penumbra 使用 OpenGL 转向尝试使用其 Graphics 上下文直接在 JPanel 上绘图。
这会很棒,除非我遇到了一些麻烦......我编译了我的代码,并且在 25 次中大约有 1 次,图形(它是示例的矩形)绘制得很好。其他〜24次,它没有。
这是我的代码:
(def main
(let [frame (JFrame. "This is a test.")
main-panel (JPanel. (GridBagLayout.))
tpan (proxy [JPanel] [] (getPreferredSize [] (Dimension. 600 400)))]
(doto frame
(set-content-pane
(doto main-panel
(grid-bag-layout
:gridx 0 :gridy 0
tpan
:gridx 0 :gridy 1
xy-label)))
(pack-frame)
(set-visible))
(draw-line tpan Color/RED 250 250 50 50)))
功能draw-line
如下:
(defn draw-line [panel color x y w h]
(let [graphics (.getGraphics panel)]
(doto graphics
(.setColor color)
(.drawRect x y w h))))
我不知道发生了什么。起初我以为是我正在研究的裁判,但后来我把它们拿出来,仍然有这些问题。我也重置了 lein 和 slime/swank 和 emacs。我很困惑。
像往常一样,任何帮助将不胜感激。我希望这是一个有答案的问题!最近,我似乎在问不可能的事情:)