有人能给我解释一下Swing和AWT的区别吗?

在某些情况下,AWT比swing更有用/更被建议使用,或者反之亦然?


当前回答

Swing vs AWT。基本上,最先出现的是AWT,它是一组重量级UI组件(意味着它们是操作系统对象的包装器),而Swing则构建在AWT之上,拥有一组更丰富的轻量级组件。

任何严肃的Java UI工作都是在Swing中完成的,而不是主要用于applet的AWT。

其他回答

Java 8

摇摆不定的

它是Java基础类的一部分 Swing是建立在AWT之上的 Swing组件是轻量级的 Swing支持可插入的外观和感觉 平台无关的 采用MVC:模型-视图-控制器架构 包:javax.swing 与Swing的其他组件不同, 它们是轻量级的,顶级容器是重量级的。

AWT -抽象窗口工具包

平台的依赖 AWT组件是重量级的 包java.awt

AWT 1。AWT占用更多的内存空间 2。AWT依赖于平台 3.AWT需要javax。awt包

波动 1。Swing占用较少的内存空间 2。Swing组件是平台独立的 3.Swing需要javax。摇摆不定的包

Swing组件提供了非常灵活的用户界面,因为它 遵循模型视图控制器(mvc)。 Awt不是基于MVC的。 Swing工作更快。 Awt的工作速度并不快。 摆动部件重量轻。 Awt组件重量很重。 Swing占用较少的内存空间。 Awt占用较多内存空间。 Swing组件是平台独立的。 Awt依赖于平台。 Swing require javax。摇摆不定的包。 Awt需要javax。awt包。

至于什么时候AWT可能比Swing -更有用

you may be targeting an older JVM or platform that doesn't support Swing. This used to really come into play if you were building Applets - you wanted to target the lowest common denominator so people wouldn't have to install a newer Java plugin. I'm not sure what the current most widely installed version of the Java plugin is - this may be different today. some people prefer the native look of AWT over Swing's 'not quite there' platform skins. (There are better 3rd party native looking skins than Swing's implementations BTW) Lots of people preferred using AWT's FileDialog over Swing's FileChooser because it gave the platform file dialog most people were used to rather than the 'weird' custom Swing one.

Swing vs AWT。基本上,最先出现的是AWT,它是一组重量级UI组件(意味着它们是操作系统对象的包装器),而Swing则构建在AWT之上,拥有一组更丰富的轻量级组件。

任何严肃的Java UI工作都是在Swing中完成的,而不是主要用于applet的AWT。