简体   繁体   English

在不扩展JFrame的情况下覆盖绘画

[英]Override paint without extending JFrame

是否可以重写paint方法,或在不扩展JFrame的情况下使用Graphics对象绘制到JFrame上?

Yes. 是。 You should extend JPanel or JComponent and override the paintComponent(...) and then add that component to the JFrame's contentPane. 您应该扩展JPanel或JComponent并覆盖paintComponent(...) ,然后将该组件添加到JFrame的contentPane中。 Leave JFrame's paint(...) method alone, and in fact you would only rarely (if ever) want to extend JFrame anyway. 不用理会JFrame的paint(...)方法,实际上,您很少会(如果有的话)仍然想扩展JFrame。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM