import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class LabelExample { public static void main(String[] args) { Shell shell = new Shell(); shell.setSize(200, 150); shell.open(); Label label = new Label(shell, SWT.NONE); label.setText("Hello World!"); label.setBounds(50, 50, 100, 20); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class LabelExample { public static void main(String[] args) { Shell shell = new Shell(); shell.setSize(200, 150); shell.open(); Label label = new Label(shell, SWT.NONE); label.setBounds(50, 50, 100, 20); for (int i = 1; i <= 10; i++) { label.setText("Count: " + i); shell.update(); Thread.sleep(1000); } while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }In this example, we create a new Label object and set its position and size using the setBounds() method. We then use a for loop to update the label's text every second, displaying a countdown from 1 to 10. The package library for the org.eclipse.swt.widgets Label class is the SWT (Standard Widget Toolkit) library, which is part of the Eclipse IDE.