SWT (jface) experience opening multiple forms

Source: Internet
Author: User

Code It is very simple, as shown below: Copy code The Code is 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 = new GC (small );
GC. setbackground (display. getsystemcolor (SWT. 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 (display. getsystemcolor (SWT. 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 code opens the sub-screen:Copy codeThe Code is 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 = 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 this book ...");
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 "};< br> final button [] radios = new button [ratings. length];
for (INT I = 0; I radios [I] = new button (dialog, SWT. radio);
radios [I]. settext (ratings [I]);
}< br> button ratebutton = new button (dialog, SWT. push);
ratebutton. settext ("rate! ");
ratebutton. addselectionlistener (New selectionlistener () {
Public void widgetselected (selectionevent e) {
for (INT I = 0; I If (radios [I]. getselection () opendialog. settext ("rating:" + ratings [I]);
dialog. close ();
}< br> Public void widgetdefaselecselected (selectionevent e) {
}< BR >});
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-dialogsize. y)/2);
}< br> Public void widgetdefaselecselected (selectionevent e) {
}< BR >});
shell. open ();
while (! Shell. isdisposed () {
If (! Display. readanddispatch () {
display. sleep ();
}< BR >}< br> display. dispose ();
}< br> Public static void main (string [] ARGs) {
New dialogshell ();
}< BR >}

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.