自IBM公司提供的跨平台GUI开发包SWT以来,越来越多受到广大程序员的亲睐,已经有不少程序员用它开发出美观、高效、实用的桌面应用程序。这让我们更有理由去探索SWT给我们带来的惊奇。

创新互联是一家专业提供志丹企业网站建设,专注与网站设计制作、成都网站设计、H5网站设计、小程序制作等业务。10年已为志丹众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。
SWT在外观和性能上都超过了Swing和AWT,为什么这样说呢?下面简单的测试程序会让你一目了然。废话也不多说,让我们看Swing和AWT程序。
下面让我们写一个简单的程序来测试一下,程序只做一件事,就是用Label显示”HelloWorld!”,我的测试环境是JDK1.5.0+Eclipse3.1。看看在SWT、Swing和AWT下分别实现该效果所需要的时间和内存消耗。
AWT_CODE:
- import java.awt.Frame;
 - import java.awt.Label;
 - import java.awt.event.WindowAdapter;
 - import java.awt.event.WindowEvent;
 - public class awtTest {
 - public static void main(String[] args) {
 - long memory = 0L;
 - long time = 0L;
 - memory = Runtime.getRuntime().freeMemory();
 - time = System.currentTimeMillis();
 - Frame frame = new Frame();
 - Label label = new Label();
 - label.setText("Hello World!");
 - frame.add(label);
 - frame.setVisible(true);
 - frame.addWindowListener(new WindowAdapter() {
 - public void windowClosing(WindowEvent we) {
 - System.exit(0);
 - }
 - });
 - frame.pack();
 - System.out.println(System.currentTimeMillis() - time);
 - System.out.println(memory - Runtime.getRuntime().freeMemory());
 - }
 - }
 
SWING_CODE:
- import javax.swing.JFrame;
 - import javax.swing.JLabel;
 - import java.awt.event.WindowAdapter;
 - import java.awt.event.WindowEvent;
 - public class swingTest {
 - public static void main(String[] args) {
 - long memory = 0L;
 - long time = 0L;
 - memory = Runtime.getRuntime().freeMemory();
 - time = System.currentTimeMillis();
 - JFrame frame = new JFrame();
 - JLabel label = new JLabel();
 - label.setText("Hello World!");
 - frame.add(label);
 - frame.setVisible(true);
 - frame.addWindowListener(new WindowAdapter() {
 - public void windowClosing(WindowEvent we) {
 - System.exit(0);
 - }
 - });
 - frame.pack();
 - System.out.print("Time:");
 - System.out.println(System.currentTimeMillis() - time);
 - System.out.print("Memory:");
 - System.out.println(memory - Runtime.getRuntime().freeMemory());
 - }
 - }
 
SWT_CODE:
- import org.eclipse.swt.widgets.Display;
 - import org.eclipse.swt.widgets.Shell;
 - import org.eclipse.swt.widgets.Label;
 - import org.eclipse.swt.SWT;
 - public class swtTest {
 - public static void main(String[] args) {
 - long memory = 0L;
 - long time = 0L;
 - memory = Runtime.getRuntime().freeMemory();
 - time = System.currentTimeMillis();
 - Display display = new Display();
 - Shell shell = new Shell(display);
 - Label label = new Label(shell, SWT.NONE);
 - label.setText("Hello World!");
 - shell.pack();
 - label.pack();
 - shell.open();
 - System.out.print("Time:");
 - System.out.println(System.currentTimeMillis() - time);
 - System.out.print("Memory:");
 - System.out.println(Runtime.getRuntime().freeMemory() - memory);
 - while(!shell.isDisposed()) {
 - if(!display.readAndDispatch()) {
 - display.sleep();
 - }
 - }
 - display.dispose();
 - label.dispose();
 - }
 - }
 
                当前名称:SWT比价Swing和AWT
                
                网页地址:http://www.csdahua.cn/qtweb/news30/128730.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网