Questions tagged «paintcomponent»

4
paintComponent如何工作?
这可能是一个非常菜鸟的问题。我才刚开始学习Java 我不了解paintComponent方法的操作。我知道是否要绘制东西,必须重写paintComponent方法。 public void paintComponent(Graphics g) { ... } 但是什么时候叫?我从未见过像“ object.paintComponent(g)”这样的东西,但是在程序运行时仍然会绘制它。 什么是Graphics参数?这个从哪里来?调用方法时必须提供参数。但是正如我之前所说,似乎从未明确调用此方法。那么谁提供这个参数呢?以及为什么我们必须将其转换为Graphics2D? public void paintComponent(Graphics g) { ... Graphics2D g2= (Graphics2D) g; ... }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.