什么是Swing和AWT的区别? [英] What is the difference between Swing and AWT?

查看:329
本文介绍了什么是Swing和AWT的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释我什么是Swing和AWT的区别?

Can someone please explain me what's the difference between Swing and AWT?

是否有建议比Swing或反之亦然使用任何情况下,AWT是比较有用/?

Are there any cases where AWT is more useful/advised to use than swing or vice-versa?

推荐答案

AWT是Java接口,原生系统界面code present在你的操作系统。它不会工作,每个系统上是相同的,尽管它会尝试。

AWT is a Java interface to native system GUI code present in your OS. It will not work the same on every system, although it tries.

Swing是一个更多或更少的纯Java的GUI。它使用AWT创建一个操作系统窗口,然后绘制按钮,标签,文本,复选框,等的图片,到该窗口并响应所有的鼠标点击,键盘输入等,决定为自己做什么而不是让操作系统处理它。因此,Swing是100%的便携式和是一样的跨平台(虽然它是换肤功能,并具有可插拔的外观和感觉,可以使它看起来或多或少怎么样的本机窗口和窗口小部件看起来)。

Swing is a more-or-less pure-Java GUI. It uses AWT to create an operating system window and then paints pictures of buttons, labels, text, checkboxes, etc., into that window and responds to all of your mouse-clicks, key entries, etc., deciding for itself what to do instead of letting the operating system handle it. Thus Swing is 100% portable and is the same across platforms (although it is skinnable and has a "pluggable look and feel" that can make it look more or less like how the native windows and widgets would look).

这是完全不同的方法来GUI工具包,有很多的后果。一个完整的回答你的问题会尝试探索所有这些。 :)这里有几个:

These are vastly different approaches to GUI toolkits and have a lot of consequences. A full answer to your question would try to explore all of those. :) Here are a couple:

AWT是一个跨平台的接口,所以尽管它使用了其功能的基础操作系统或本地GUI工具包,它不提供访问所有内容,这些工具包可以做。可能在一个平台上存在的高级或更新AWT小部件可能无法在另一种支持。这是不一样的每个平台上的小部件的功能可能不支持,或者更糟的是,他们可能会有所改变每个平台上。用来投资了很多的精力来获得他们的AWT应用程序跨平台工作始终的人 - 比如,他们可能会尝试从Java拨打电话进入本地code

AWT is a cross-platform interface, so even though it uses the underlying OS or native GUI toolkit for its functionality, it doesn't provide access to everything that those toolkits can do. Advanced or newer AWT widgets that might exist on one platform might not be supported on another. Features of widgets that aren't the same on every platform might not be supported, or worse, they might work differently on each platform. People used to invest lots of effort to get their AWT applications to work consistently across platforms - for instance, they may try to make calls into native code from Java.

由于AWT使用本地GUI窗口小部件,您的操作系统知道它们和处理将它们放在对方面前,等等,而Swing小部件都是从看你的操作系统的点在窗口内无意义的像素。摆动本身处理您的小工具的布局和堆叠。混合AWT和Swing是非常不支持,并可能导致荒谬的结果,例如,在对话框中其他一切都模糊不清在其居住,因为一切是使用Swing创建的本机的按钮。

Because AWT uses native GUI widgets, your OS knows about them and handles putting them in front of each other, etc., whereas Swing widgets are meaningless pixels within a window from your OS's point of view. Swing itself handles your widgets' layout and stacking. Mixing AWT and Swing is highly unsupported and can lead to ridiculous results, such as native buttons that obscure everything else in the dialog box in which they reside because everything else was created with Swing.

由于摆动试图做在Java中一切可能比本地GUI窗口提供的非常原始图形程序等,它曾经招致相比AWT相当的性能损失。这使得摇摆捉对不幸缓慢。然而,这在过去几年中大幅缩水,由于更优化的JVM,更快的机器,和(我presume)Swing的内部优化。今天Swing应用程序可以跑得不够快,从使用本机部件的应用维修,甚至比比,而且几乎没有什么区别。有些人会说花了太长时间才能到这一点,但大多数人会说,这是非常值得的。

Because Swing tries to do everything possible in Java other than the very raw graphics routines provided by a native GUI window, it used to incur quite a performance penalty compared to AWT. This made Swing unfortunately slow to catch on. However, this has shrunk dramatically over the last several years due to more optimized JVMs, faster machines, and (I presume) optimization of the Swing internals. Today a Swing application can run fast enough to be serviceable or even zippy, and almost indistinguishable from an application using native widgets. Some will say it took far too long to get to this point, but most will say that it is well worth it.

最后,你可能也想看看SWT(使用Eclipse的GUI工具包,以及双方AWT和Swing的替代),这是有点回归到通过Java访问本机的窗口小部件的AWT想法。

Finally, you might also want to check out SWT (the GUI toolkit used for Eclipse, and an alternative to both AWT and Swing), which is somewhat of a return to the AWT idea of accessing native Widgets through Java.

这篇关于什么是Swing和AWT的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆