SWT (JFace) Experience opens multiple Form_java programming

Source: Internet
Author: User
Tags sleep
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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.