The code is simple, as follows:
Copy Code code as follows:
Package swt_jface.demo1;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.graphics.GC;
Import Org.eclipse.swt.graphics.Image;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Shell;
public class Main {
public static void Main (string[] args) {
Display display = new display ();
Image small = new Image (Display, 16, 16);
GC GC = new GC (small);
Gc.setbackground (SWT, Display.getsystemcolor. color_red));
Gc.fillarc (0, 0, 16, 16, 45, 270);
Gc.dispose ();
Image large = new Image (display, 32, 32);
GC = new GC (large);
Gc.setbackground (SWT, Display.getsystemcolor. Color_blue));
Gc.fillarc (0, 0, 32, 32, 45, 270);
Gc.dispose ();
Shell shell = new shell (display);
Shell.settext ("Small and Large Icons");
Shell.setimages (new image[] {small, large});
Shell shell2 = new Shell (display);
Shell2.settext ("Small icon");
Shell2.setimage (small);
Shell.open ();
Shell2.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ())
Display.sleep ();
}
Display.dispose ();
}
}
The following is the code that opens the sprites:
Copy Code code as follows:
Package swt_jface.demo1;
Import Org.eclipse.swt.SWT;
Import org.eclipse.swt.events.SelectionEvent;
Import Org.eclipse.swt.events.SelectionListener;
Import Org.eclipse.swt.graphics.Point;
Import Org.eclipse.swt.graphics.Rectangle;
Import Org.eclipse.swt.layout.RowLayout;
Import Org.eclipse.swt.widgets.Button;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Shell;
public class Dialogshell {
Public Dialogshell () {
Display display = new display ();
Final Shell shell = new shell (display);
Shell.setlayout (New Rowlayout ());
Shell.setsize (500, 200);
Final button OpenDialog = New button (Shell, SWT. PUSH);
Opendialog.settext ("Click here to Rate");
Opendialog.addselectionlistener (New Selectionlistener () {
public void widgetselected (Selectionevent e) {
Final Shell Dialog = new Shell (shell, SWT). Dialog_trim | Swt. Application_modal);
Dialog.setlayout (New Rowlayout ());
Final string[] Ratings =
New string[] {"killer!", "Good Stuff", "so-so", "Needs work"};
Final button[] radios = new Button[ratings.length];
for (int i = 0; i < ratings.length; i++) {
Radios[i] = new Button (dialog, SWT. RADIO);
Radios[i].settext (Ratings[i]);
}
Button Ratebutton = New button (dialog, SWT. PUSH);
Ratebutton.settext ("rate!");
Ratebutton.addselectionlistener (New Selectionlistener () {
public void widgetselected (Selectionevent e) {
for (int i = 0; i < radios.length; i++)
if (Radios[i].getselection ()) Opendialog.settext ("Rating:" + ratings[i]);
Dialog.close ();
}
public void widgetdefaultselected (Selectionevent e) {
}
});
Dialog.pack ();
Dialog.open ();
Rectangle shellbounds = Shell.getbounds ();
Point dialogsize = Dialog.getsize ();
Dialog.setlocation (shellbounds.x + (shellbounds.width-dialogsize.x)/2, Shellbounds.y + (Shellbounds.height-dialogsi ZE.Y)/2);
}
public void widgetdefaultselected (Selectionevent e) {
}
});
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Dialogshell ();
}
}