Developing Java-based graphical user interface _jsp programming

Source: Internet
Author: User
SWT (Standard Widget Toolkit) is IBM's "java-based" graphical interface development library, I said it is "java-based" meaning that programmers write code is the use of the Java language, in fact, SWT's low-level implementation is C language complete. But these are transparent to programmers.

When we use SWT to develop GUI programs, we write them directly with the SWT API. In fact, many Java code is removed with the C code through JNI. For different platforms each class has a different implementation, the purpose of this article is not to tell the principles of SWT design, if you are interested in these can refer to http://www.eclipse.org/articles/Article-SWT-Design-1/ Swt-design-1.html.

Let's begin by introducing how to use SWT, first I assume you have installed Eclipse3.0, of course other versions can also, if not yet www.eclipse.org up to download.

Run Eclipse, switch to the bottom of the Java perspective, and create a new Java project from package explore. The name is test.

In libraries, select Add external jars to add the class libraries that are required to run SWT, which is related to the system, such as my Windows XP address: D:eclipsepluginsorg.eclipse.swt.win32_ 3.0.0wswin32swt.jar. Add it in, suggest to do a variables point to this Swt.jar file, add variables directly later on.

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 (display);
Label label = new label (Shell, SWT. NONE);
Label.settext ("Hello, world!");
Shell.pack ();
Label.pack ();
Shell.open ();
while (!shell.isdisposed ())
if (!display.readanddispatch ())
Display.sleep ();
Display.dispose ();
Label.dispose ();
}
}

Configure the operating environment, because the SWT program to run the use of native resources, if you are running the above program will appear when the error, similar to Java.lang.UnsatisfiedLinkError:no swt-win32-2133 in Java.library.path ", so you have to specify the location of the DLL you want, by switching from menu Run->run to running Configuration interface, selecting arguments in VM Arguments inside Write-djava.library.path= For example, the address of the DLL on my machine is d:eclipsepluginsorg.eclipse.swt.win32_3.0.0oswin32. This is a bit of a hassle to configure for each run, so it is recommended that you add the path including the DLL to the environment variable path.

Run the program and you will see the effect of your first program: I feel pretty good, faster than SWING/AWT.

about how to use SWT, please refer to the relevant articles above www.eclipse.org, read more AWT API, write more code!

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.