Swt1-Introduction To SWT
Swt1-Introduction To SWT
INTRODUCTION
TO SWT
1. SWING VS SWT
In earlier version of JDK, the functions of graphical user interface have been
greatly expanded to form a complete set of API collections, called Java
foundation class (JFC).
The earliest GUI tool set provided by Java is AWT (Abstract window toolkit).
This package provides a set of interfaces to interact with the local graphical
interface.
It is the basic tool provided by java to establish and set up the graphical user
interface of Java.
ABOUT AWT…
There is a one-to-one correspondence between the graphics function in AWT
and the graphics function provided by the operating system, which is called
peers.
When using AWT to write the graphical user interface, it is actually using the
graphics library provided by the local operation system.
different operating systems have different interfaces (different style), even
different functions
SWING
Swing component is an extension of AWT component, which provides many
new graphical user interface components.
Swing components are implemented in pure Java, and their performance is
consistent on different platforms.
Swing component has no local code, does not depend on the support of
specific local operating system, and has the ability to provide other features
not supported by local system, which is the biggest difference between Swing
component and AWT component.
Disadvantages: the appearance or style provided by Swing is incompatible with the
local system.
SWT
SWT is an open source widget toolkit for Java designed to provide efficient,
portable access to the user-interface facilities of the operating systems on
which it is implemented.
Download website: https://www.eclipse.org/swt/
WHAT’S DIFFERENT
SWT uses the widgets provided by the operating system to render its graphical
application. The object in the control class has a direct counterpart in the
operating system, which can be used through the handle of the class.
In addition to the control class, SWT also provides many components. The
specific hierarchy is shown in Figure 1-1
Widget
3) WindowBuilder:
6 ) org.eclipse.swt.ole.win32
http://www.eclipse.org/windowbuilder/download.php
URL: https://download.eclipse.org/windowbuilder/1.9.7/
SWT PROGRAM
DEVELOPMENT STEPS
Let's take a look at how to develop an SWT application using Eclipse, which con-
sists of the following four steps:
1) New Java project: HelloLabel;
2) Set the construction path of the project
Right-click on the project name, Build Path Configure Build Path, click Add Ex-
ternal JARs;
Positioning to the eclipse \ plugins in the org. Eclipse. SWT. Win32. Win32. X86_3.
100.1 v4236b. Jar and org. Eclipse swt_3. 100.1 v4236b. Jar;
3) Create a new class HelloLabel.
Here's the code
3. MVC PATTERN VERSUS SWT
The model, view, and control classes in MVC are shown below:
3. MVC PATTERN VERSUS SWT
Model-view-controller (MVC: Model-View-Controller) is a
structural organization Model of interactive interfaces.
MVC, proposed by Trygve Reenskaug, was first applied in the
Smalltalk-80 environment, making many interaction and interface
systems form the basis. Microsoft's MFC basic classes also follow
the IDEA of MVC.
For the need of interface design variability, MVC decomposes the
composition of interactive system into model, view and control
components.
3. MVC PATTERN VERSUS SWT
Now combine Java SWT to illustrate the MVC design pattern:
Model: Is the place where SWT component data is stored. For example, the
Table Model stores all data on the Table. Responsible for data
maintenance. Models typically provide methods for accessing and modifying
data. The model also sends events to the registered views as the model
changes, and the views update themselves based on the model changes.
View: refers to the appearance of SWT components. Responsible for provid-
ing viewable views of part of the model's data.
Controller: Handles events for the view in response to user actions on the
SWT component. Swing listeners such as mouse and action listeners are
MVC controllers.