资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

SWT、Swing和AWT有什么区别

这篇文章将为大家详细讲解有关SWT、Swing和AWT有什么区别,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

十多年的慈溪网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整慈溪建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“慈溪网站设计”,“慈溪网站推广”以来,每个客户项目都认真落实执行。

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

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有什么区别”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


新闻名称:SWT、Swing和AWT有什么区别
标题链接:http://cdkjz.cn/article/pgehhh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220