This section provides the source code for a simple eSWT Hello World
MIDlet created with the eSWT MIDlet starter. The MIDlet displays a Label
with the static text
"Hello, world!" and shows an exit Command
within a complete event loop.
You can download the Eclipse and NetBeans project files for the eSWT Hello World MIDlet by clicking here.
Figure: eSWT Hello World MIDlet
import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.ercp.swt.mobile.Command; public class HelloWorld extends SWTMIDlet { public void runUI(Display display) { Shell shell = new Shell(display); Command exitCommand = new Command(shell, Command.EXIT, 0); exitCommand.setText("Exit"); exitCommand.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { exit(); } public void widgetDefaultSelected(SelectionEvent arg0) { } }); shell.setLayout(new FillLayout()); Label label = new Label(shell, SWT.HORIZONTAL); label.setText("Hello, world!"); shell.open(); } }
For more information about the SWTMIDlet
class, see section eSWT MIDlet starter.