Step-by-step uses SWT development GUI

zhaozj2021-02-16  73

SWT (Standard Widget Toolkit) is the "Java" graphical interface development library launched by IBM. I said that it is "Java" means that when programmers write code, use Java language, in fact the bottom level of SWT It is completed in C language. But these are transparent to programmers.

When we use the SWT to develop the GUI program, we will write directly with the SWT API. In fact, many Java code is implemented by JNI to remove C code. There are different implementations for each class for different platforms. The purpose of this article is not to describe the design principle of SWT. If you are interested in these, you can refer to http://www.eclipse.org/articles/article-swt -Design-1 / swt-design-1.html.

Here, you will start to use SWT, first of all, I assume that you have installed Eclipse3.0, of course, other versions can be downloaded, if you haven't yet, you can download it from www.eclipse.org.

Run Eclipse, switch to the Java perspective, new Java Project from Package Explore. Name Test In Libraries Select Add External Jars to add the class library required to run SWT, this and the system are related, for example, under Windows XP, the address is: D: /Eclipse/plugins/org.eclipse.swt.win32_3 .0.0 / ws / win32 / swt.jar. Add it to it, it is recommended to make a variables point to this swt.jar file, and add Variables directly to write Java code, such as import org.eclipse.swt.widgets. *; Import org.eclipse.swt. *; Public class SWTHELLO {public static void main (string [] args) {display display = new display (); shell shell = new shell (label label = new label (shell, swt.none); label.settext ("Hello, World! "); Shell.Pack (); label.pack (); shell.Open (); while (! Shell.iedisposed ()) if (! Display.readanddispatch ()) display.sleep (); display.dispose (); label.dispose ();}} Configure the running environment. Because the SWT program is used to use this unit, if you now run the above program, there will be an error, similar to java.lang.unsatisfiedlinkerror: no SWT-win32-2133 in java.library.path, so you must specify the location you need, the specific practice is: Switch from the menu Run-> Run to the Run Configuration interface, select Arguments to write in VM Arguments - DJAVA .library.path = For example, on my machine DLL's address is d: /eclipse/plugins/org.eclipse.swt.win32_3.0.0/OS/Win32/x86. This time you run To configure a bit trouble, it is recommended that you add this path to the DLL in the environment variable Path. Run the program, you will see your first program :) My feel is quite good, speed is better than swing / AWT is fast.

转载请注明原文地址:https://www.9cbs.com/read-14863.html

New Post(0)