Java Reference
In-Depth Information
org.eclipse.swt.widgets.Display singleton can contain one or
more shells which can contain other shells and other types of widget.
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class eSWTExamplet extends MIDlet implements Runnable,
SelectionListener, PaintListener {
private Display display;
private Shell shell;
private Thread eSWTUiThread;
private boolean exit = false;
public void startApp() {
// start a Thread in which eSWT will execute its event loop
if (eSWTUiThread == null) {
eSWTUiThread = new Thread(this);
} ...
public void run() {
// init eSWT core objects
display = new Display();
shell = new Shell(display);;
// init rendering of the "Hello World"
// allow eSWT to execute the event loop
while (!exit) {
if (!display.readAndDispatch()) {
} // perform cleanup required for eSWT objects
} ...
public void paintControl(PaintEvent e) {
e.gc.setForeground(new Color(display, 255, 0, 0));
e.gc.drawText("Hello eSWT!", 0, 0, SWT.DRAW_TRANSPARENT);
As you can see in the example code, eSWT MIDlets implement the
MIDlet lifecycle methods just like any other MIDP MIDlets. When the
MIDlet enters the active state for the first time, it creates the eSWT appli-
cation UI thread, which constructs a single org.eclipse.swt.wid-
gets.Display instance that is not disposed of until the MIDlet enters
the destroyed state. Before exiting, the eSWT widgets and objects must
generally be manually deallocated by calling the dispose() method.
Search WWH ::

Custom Search