简体   繁体   中英

Canvas on JFrame in java

I've seen in many threads it's not recommended to mix awt and swing components. However I've seen examples in which they add the Canvas to a JFrame (No other swing components are involved). Canvas is an awt component and JFrame is a swing component, so is it ok to do so? and if not, how exactly to use the Canvas?

You could get some unusual display problems with older JDKs, but mixing swing and AWT is fine nowadays. See this article: http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html

I've written a game which used swing components for most of the UI/controls but a canvas for drawing the main game area (see https://github.com/qwerky/Towers/blob/master/src/main/java/lineup/ui/UI.java ). It worked fine with no problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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