[Eclipse notes] a simplest SWT program

xiaoxiao2021-03-06  17

Let's take a look at the simplest SWT program:

Package sean.test.swt; import org.eclipse.swt.widgets.display; import org.eclipse.swt.widgets.shell;

public

Class

Simplestswt

{Public static void main (string [] args) {Display Display = new display (); shell shell = new shell; shell.pack (); shell.Open (); while (! Shell.isdisposed ()) {If (! Display.readddispatch ()) {Display.sleep ();}} DISPLAY.DISPOSE ()}}

This code will display an empty form when running. What is interesting is shell shell = new shell (display); this sentence, through it we can learn: In SWT, the child control will pass to the mother-controlled reference to the child control, further, in one mother When the control is destroyed, the contained self-control is automatically destroyed. Almost all common SWT controls are handled in this way. Since SWT uses OS comes with the OS's creation and destruction of SWT controls, it is different from pure Java.

Before I contact SWT, I always feel that it is out of reach, I really feel that the specific code will be found. It turns out that it is within easy reach.

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

New Post(0)