SWT (Standard Widget Toolkit) is a "java-based" graphical interface development library launched by IBM. The reason why I say it is "java-based" means that programmers use the java language when writing code. In fact, the underlying implementation of SWT is completed in C language. But these are transparent to programmers.
When we use SWT to develop GUI programs, we directly use the SWT API to write. In fact, many Java codes are implemented through JNI removal and C code. Each class has different implementation methods for different platforms. The purpose of this article is not to talk about the design principles of SWT. If you are interested in these, you can refer to /articles/Article-SWT-Design-1/.
Let’s start by introducing how to use SWT. First of all, I assume that you have Eclipse 3.0 installed. Of course, other versions are also OK. If you don’t have one, download them from the top.
Run Eclipse, switch to the Java perspective view, and create a new java project from Package explore. The name is Test.
In Libraries, select Add external JARs to add the class library required to run SWT. This is related to the system. For example, I am under Windows XP, the address is: D:.win32_3.0. Add it in, it is recommended to make variables point to this file, and then add variables directly in the future.
Write java code, e.g.
import .*;
import .*;
public class SWTHello {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, );
("Hello, World!");
();
();
();
while(!())
if(!())
();
();
();
}
}
Configure the running environment. Since the SWT program needs to use native resources when running, if you run the above program now, an error will occur, similar to: no swt-win32-2133 in ", so you must specify the location of the required DLL. The specific method is: switch from the menu run->run to the run configuration interface, select Arguments to write in VM Arguments -=For example, the address of the DLL on my machine is D:.win32_3.0.0oswin32. This makes it a bit troublesome to configure every time you run it, so it is recommended that you add this path including DLL in the environment variable PATH.
Run the program and you will see the effect of your first program :) I feel it is pretty good, faster than Swing/AWT.
Regarding how to use SWT, please refer to the related articles above, take a look at the AWT API and write more code!
When we use SWT to develop GUI programs, we directly use the SWT API to write. In fact, many Java codes are implemented through JNI removal and C code. Each class has different implementation methods for different platforms. The purpose of this article is not to talk about the design principles of SWT. If you are interested in these, you can refer to /articles/Article-SWT-Design-1/.
Let’s start by introducing how to use SWT. First of all, I assume that you have Eclipse 3.0 installed. Of course, other versions are also OK. If you don’t have one, download them from the top.
Run Eclipse, switch to the Java perspective view, and create a new java project from Package explore. The name is Test.
In Libraries, select Add external JARs to add the class library required to run SWT. This is related to the system. For example, I am under Windows XP, the address is: D:.win32_3.0. Add it in, it is recommended to make variables point to this file, and then add variables directly in the future.
Write java code, e.g.
import .*;
import .*;
public class SWTHello {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, );
("Hello, World!");
();
();
();
while(!())
if(!())
();
();
();
}
}
Configure the running environment. Since the SWT program needs to use native resources when running, if you run the above program now, an error will occur, similar to: no swt-win32-2133 in ", so you must specify the location of the required DLL. The specific method is: switch from the menu run->run to the run configuration interface, select Arguments to write in VM Arguments -=
Run the program and you will see the effect of your first program :) I feel it is pretty good, faster than Swing/AWT.
Regarding how to use SWT, please refer to the related articles above, take a look at the AWT API and write more code!