Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以覆盖paint方法,或者在不扩展JFrame的情况下使用Graphics对象绘制到JFrame上?
是的。您应该扩展 JPanel 或 JComponent 并覆盖paintComponent(...),然后将该组件添加到 JFrame 的 contentPane。不理会 JFrame 的paint(...)方法,事实上您只是很少(如果有的话)想要扩展 JFrame。
paintComponent(...)
paint(...)