Stepping into the Swt/jface world, what are you waiting for

Source: Internet
Author: User
Tags win32

This article mainly discusses one of GUI graphics libraries in Java: Swt/jface. In the first part of this article, you will explain what swt/jface is and how to install Swt/jface. The second part of this article discusses how to use Swt/jface to write GUI programs in an instance.

One, into the Swt/jface world

1. What is Swt/jface

Java is a powerful programming language. But strong means complex, especially with Java-related nouns like the stars in the sky, the number is not over. In this paper, there are two more commonly used nouns swt and jface. Putting SWT and JFace together in the title does not mean that SWT and jface are meant to be, but that they are closely related.

There are three main types of java-based graphics libraries, namely swing, AWT, and SWT. The first two of them were published by Sun along with the JDK, while SWT was a subproject of Eclipse, an Open-source project led by IBM (now out of IBM). SWT's execution efficiency is very high. This is because SWT's bottom layer is written by C. Because SWT calls the system layer GUI API directly through C. Therefore, using SWT to write GUI programs is identical in appearance to the program written using C + +, Delphi (under Windows). It's similar to AWT. AWT is also the GUI API that uses C to invoke the system layer directly at the bottom. But they are different, the biggest difference may be that one is provided by Sun, and one is from eclipse. This means that if you use AWT, as long as you have a JDK or JRE installed on your machine, you do not need to bring other libraries when you release the software. And how to use SWT, you must bring the SWT *.dll (Windows version) or *.so (Linux/unix version) file and the associated *.jar package at the time of publication. What's more, there are some differences in the graphics interface they provide. SWT may be richer, and we can see the eclipse interface as we know it. However, with the continuous updating of the AWT library, the ability of AWT's graphics performance is increasing.

Although SWT is powerful, it is relatively low-level. In other words, some of its functions in the use of relatively low-level, not too consistent with object-oriented features. Therefore, JFace was developed on the basis of SWT. JFace a certain expansion in SWT. Therefore, it can also be said that JFace is based on SWT, as in VC using MFC to wrap the WIN32 API.

Installation of 2.swt/face

When you publish a GUI program that is written using swt/jface, you need to bring the appropriate library file with your program. For the Windows version of SWT, SWT contains 4 DLL files and a jar file. They are Swt-awt-win32-3305.dll, Swt-gdip-win32-3305.dll, Swt-wgl-win32-3305.dll, Swt-win32-3305.dll and Swt.jar. When publishing, you want to put 4 DLL files in the path path, or use-djava.library.path to set the appropriate path. Place the Swt.jar in the Classpath path, or use-classpath to set the appropriate jar package. For JFace, there are 5 jar packages in addition to the 5 files listed above:

org.eclipse.core.runtime_3.1.2.jar
org.eclipse.jface_3.1.1.jar
org.eclipse.jface.text_3.1.2.jar
org.eclipse.osgi_3.1.2.jar
org.eclipse.text_3.1.1.jar

These 5 jar packages can all be found in Eclipse's plugins directory, and the version number after these 5 files may vary depending on the version number of Eclipse, but the previous section is the same. Readers should be aware of this when looking for these jar packs.

SWT's development packages can be downloaded individually from http://www.eclipse.org or replicated from Eclipse's plugins directory. The JFace development package does not provide a separate download, so the JFace development package must be available from the plugins directory.

Second, let's write the first program.

The best way to learn a new technology is to use it. Now let's use SWT and jface to implement the same program separately. This program is a simple Notepad program. There are three buttons on it, "New key", "open", "save", and the following is a text box for editing text information. Now let's take a look at the program interface that is implemented using SWT:

Figure 1 The Notepad program interface implemented with SWT

How to look at the above interface is not and with Delphi, VC do the interface exactly the same!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.