Swt/jface Development Guide Understanding display and shell

Source: Internet
Author: User
Tags pack

In this section, we start with some preliminary explorations of SWT from the Hello, world! program listed earlier. The so-called initial point is that we will introduce the basic ideas for the preparation of SWT programs, as well as the two important classes: display and Shell to make some introductions.

Because this section and the previous section are posted in two parts, I still have the Hello, world! snippet listed below:

1package swtjfacesample;
2
3import org.eclipse.swt.SWT;
4import org.eclipse.swt.widgets.Display;
5import org.eclipse.swt.widgets.Shell;
6import org.eclipse.swt.widgets.Text;
7
8public class HelloSwt {
9 /**//**
10 * Hello,world!
11 *
12 * @param args
13 */
14 public static void main(String[] args) {
15 Display display = new Display();
16 Shell shell = new Shell(display);
17
18 Text helloText = new Text(shell, SWT.CENTER);
19 helloText.setText("Hello,World!");
20 helloText.pack();
21
22 shell.pack();
23 shell.open();
24
25 while (!shell.isDisposed()) {
26 if (!display.readAndDispatch()) {
27 display.sleep();
28 }
29 }
30 display.dispose();
31
32 }
33}

Code Snippet 2

Although this program is simple, it reflects the steps we have made to write the SWT program, these steps are:

1. Create a Display object

2. Create one or more shell objects, and you can assume that the shell represents the window of the program.

3. Create various parts (widgets) within the shell

4. Initialize each part (appearance, status, etc.) while creating a listener for events for various parts (L5. Call the Shell object's open () method to display the form

6. Various events are monitored and processed until the program issues an exit message

7. Call the Dispose () method of the display object to end the program.

Related Article

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.