Why does calling dispose() on Graphics object cause JPanel to not render any components

后端 未结 2 1234
[愿得一人]
[愿得一人] 2020-12-02 00:43

After learning that dispose() should be called on Graphics/Graphics2D object after use, I went about changing my game to incorporate t

相关标签:
2条回答
  • 2020-12-02 00:48

    The thing is that the Graphics context you are using in paintComponent is created and provided by the caller (the framework), which is also responsible for disposing of it.

    You only need to dispose of Graphics when you actually create it yourself (for example by calling Component.getGraphics()). In your case, you're not creating it, you're just casting it, so do not call dispose in this case.

    0 讨论(0)
  • 2020-12-02 00:53

    Because .dispose() releases your resources. Yes, everything.

    0 讨论(0)
提交回复
热议问题