In the GUI system of any operating platform, the access operations of the component or some graphics API are strictly synchronized and serialized. For example, the button member in a graphical interface can be set into an enabled or disabled state (disable), the normal processing method is that the user is placed in the Event processing queue of the GUI system. (This means that the access operation is serialized), then processes (this means that the access operation is synchronized). Imagine When the set function of the button can be used, the program wants to set the button again to disable the status, which will inevitably cause a conflict. In fact, this operation will trigger an exception in any GUI system.
The Java language itself provides a multi-threaded mechanism, which is unfavorable to the GUI programming, which does not guarantee synchronization and serialization of the graphics component operation. SWT uses a simple and straightforward way to adapt to the local GUI system to the thread: in SWT, there is usually a unique thread called "user thread", only in this thread, can call the component or some The access operation of the graphics API. If the program is called directly in the non-user thread, then SwTexcepiton will be thrown. However, SWT is also available in the * .widget.display class, two methods can be indirectly available to the access operation of the graphics component of the non-user thread, which is the two methods of syncexec (runnable) and asyncExec (runnable) to implement of. E.g:
/ / This time the program runs in a non-user thread and wants to join a button on the component panel.
Display.getCurrent (). AsyncExec (New Runnable () {
Public void run () {
Button Butt = New Button (Panel, SWT.PUSH);
Butt.Settext ("Push");
}
});
Methods Syncexec () and Asyncexec () The difference is that the former is returned after the specified thread is executed, and the latter returns to the current thread immediately regardless of whether the specified thread is executed.
SWT extension: jface
JFACE and SWT relationships are better than Microsoft's MFC and SDK, and JFACE is based on SWT development, and its API is more easy to use than SWT, but the function is not SWT. Direct. For example, the following code Apply the MessageDialog in the JFACE Opens a Warning dialog:
MessageDialog.Openwarning (Parent, "Warning", "Warning Message");
If you only complete the above features with SWT, the statement will not be less than 30 lines!
JFACE is originally a set of APIs written for more convenient use of SWT, which is the main purpose to develop an Eclipse IDE environment, not to apply to other independent applications. So before the Eclipse version 2.1, it is difficult to peel out the JFACE API completely from the Eclipse's kernel API. It always imports more less than the Eclipse core code class or interface other than JFAce can get a JFACE without any compilation. Develop bag. However, the Eclipse organization seems to have gradually realized that JFACE's important role in developing an independent application. In the 2.1 version developed, JFACE has also begun to become a completely independent development package as SWT, but this development package is also In the change (the author's Eclipse2.1m3 version) is applied. The packet prefix for the JFACE development package is starting with org.eclipse.jface. The JAR package and source code are also like SWT, as well as to your Eclipse installation path} / plugins path.
For developers, when developing a graphics component, a better way is to find a first to JFACE packages, see if there is a more concise implementation method, if you don't use the SWT package to achieve it. For example, JFACE provides a good support for the dialog box, except for various types of dialogs (such as the MessageDialog with the top, or with a Title Bar), if you want to implement a custom dialog, it is best to The Dialog class in JFACE inherits, not from * .widget.dialog in SWT. Applying the classes in the Preference package in JFACE easy to make your own software a very professional configuration dialog. For Tree, Table and other graphics components, they also need to be associated with data, such as data displayed in Table, providing this type of model-view mode for this type of component in the View packet in JFACE, this method Separate display and data, more development and maintenance. The most features in JFACE are the processing of text content. Dozens of dozens of text processing related classes can be found in org.eclipse.jface.text. *.
More coming with the app
The Java program is usually published in the way in the Class file, running the Class requires JRE or JDK support. This is another fatal weakness of the Java GUI program, imagine that the app for the majority of users, no matter how simple your program features, or your code is very streamlined, you have to let users go Download a 7, 8M JRE, that is frustrating. And for programmers, Class usually means exposure to source code, anti-compilation tools make those people who are tuned easily to get your source code. Although there are many encryption methods for Class, it is always expensive for sacrifice performance. Fortunately, there are other ways available: compile the class into an EXE file!
Reference 3 provides a detailed approach to applying GCJ to compile SWT into an EXE file. As a supplement to that article, it is currently available to GCJ under Windows by downloading Cygwin. Excelsior is also a very good compiler that the author used, the only regret is its price!
The advantages of the SWT development kit, simple, cross-platform, reliable, and other Java language itself are gradually blended into applications developed to the graphical interface. Therefore, I believe that the door of another success in the Java language is gradually opening.
Reference:
Http://www.e2one.com Polar Software Studio Apps SWT & JFACE API Developed Enterprise Real-Time Communication IM software, is an example of SWT & JFACE develops a Standalone program.
Http://www.eclipse.org/Articles/swt-design-2/swt-design-2.html This article details how SWT developers manage system resources.
http://www-900.ibm.com/developerworks/cn/linux/guitkit/j-nativegui/index.shtml describes how to apply the SWT program to GCJ compile the cost of the machine application file.
http://www-900.ibm.com/developerWorks/cn/java/l-eclipse/index.shtml introduces the use of Eclipse and the simple plugin development process.
Www.eclipse.org All about Eclipse, SWT, JFACE can find the answer here. It is also a website to download the Eclipse development environment.
Http://www.cygwin.com/ You can get the Windows version of GCJ.
About author
Ni Dapeng, has many years of software development experience, of which the time in the past four years is concentrated in Java related technologies. You can contact him through e-mail: ndp@e2one.com.