Java by API/org.eclipse.swt.widgets/MessageBox

Материал из Java эксперт
Перейти к: навигация, поиск

MessageBox: open()

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Shell s = new Shell();
   MessageBox messageBox = new MessageBox(s, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
   messageBox.setMessage("Do you really want to exit?");
   messageBox.setText("Exiting Application");
   int response = messageBox.open();
   if (response == SWT.YES)
     System.out.println(SWT.YES);
   else if(response == SWT.NO)
     System.out.println(SWT.NO);
 }

}

      </source>
   
  
 
  



MessageBox: setMessage(String mess)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Shell s = new Shell();
   MessageBox messageBox = new MessageBox(s, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
   messageBox.setMessage("Do you really want to exit?");
   messageBox.setText("Exiting Application");
   int response = messageBox.open();
   if (response == SWT.YES)
     System.out.println(SWT.YES);
   else if(response == SWT.NO)
     System.out.println(SWT.NO);
 }

}

      </source>
   
  
 
  



MessageBox: setText(String text)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Shell s = new Shell();
   MessageBox messageBox = new MessageBox(s, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
   messageBox.setMessage("Do you really want to exit?");
   messageBox.setText("Exiting Application");
   int response = messageBox.open();
   if (response == SWT.YES)
     System.out.println(SWT.YES);
   else if(response == SWT.NO)
     System.out.println(SWT.NO);
 }

}

      </source>
   
  
 
  



new MessageBox(Shell parent, int style)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Shell s = new Shell();
   MessageBox messageBox = new MessageBox(s, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
   messageBox.setMessage("Do you really want to exit?");
   messageBox.setText("Exiting Application");
   int response = messageBox.open();
   if (response == SWT.YES)
     System.out.println(SWT.YES);
   else if(response == SWT.NO)
     System.out.println(SWT.NO);
 }

}

      </source>
   
  
 
  



new MessageBox(shell, SWT.ABORT | SWT.RETRY | SWT.IGNORE)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell, SWT.ABORT | SWT.RETRY | SWT.IGNORE);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}

      </source>
   
  
 
  



new MessageBox(shell,SWT.ICON_ERROR)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell,SWT.ICON_INFORMATION);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}


      </source>
   
  
 
  



new MessageBox(shell,SWT.ICON_QUESTION)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell,SWT.ICON_QUESTION);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}

      </source>
   
  
 
  



new MessageBox(shell,SWT.ICON_WARNING)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell,SWT.ICON_WARNING);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}

      </source>
   
  
 
  



new MessageBox(shell,SWT.ICON_WORKING)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell,SWT.ICON_WORKING);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}

      </source>
   
  
 
  



new MessageBox(shell, SWT.OK)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell, SWT.OK);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}


      </source>
   
  
 
  



new MessageBox(shell, SWT.OK | SWT.CANCEL)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell, SWT.OK | SWT.CANCEL);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}

      </source>
   
  
 
  



new MessageBox(shell, SWT.RETRY | SWT.CANCEL)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell, SWT.RETRY | SWT.CANCEL);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}


      </source>
   
  
 
  



new MessageBox(shell, SWT.YES | SWT.NO)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}


      </source>
   
  
 
  



new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL);
   mb.setText("Message from SWT");
   mb.setMessage("message body");
   int val = mb.open();
   String valString = "";
   switch (val) {
   case SWT.OK:
     valString = "SWT.OK";
     break;
   case SWT.CANCEL:
     valString = "SWT.CANCEL";
     break;
   case SWT.YES:
     valString = "SWT.YES";
     break;
   case SWT.NO:
     valString = "SWT.NO";
     break;
   case SWT.RETRY:
     valString = "SWT.RETRY";
     break;
   case SWT.ABORT:
     valString = "SWT.ABORT";
     break;
   case SWT.IGNORE:
     valString = "SWT.IGNORE";
     break;
   }
   System.out.println(valString);
   shell.close();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

}


      </source>