Java by API/org.eclipse.swt.widgets/MessageBox — различия между версиями

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

Текущая версия на 14:16, 31 мая 2010

MessageBox: open()

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);
  }
}





MessageBox: setMessage(String mess)

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);
  }
}





MessageBox: setText(String text)

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);
  }
}





new MessageBox(Shell parent, int style)

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);
  }
}





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

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();
  }
}





new MessageBox(shell,SWT.ICON_ERROR)

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();
  }
}





new MessageBox(shell,SWT.ICON_QUESTION)

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();
  }
}





new MessageBox(shell,SWT.ICON_WARNING)

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();
  }
}





new MessageBox(shell,SWT.ICON_WORKING)

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();
  }
}





new MessageBox(shell, SWT.OK)

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();
  }
}





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

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();
  }
}





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

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();
  }
}





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

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();
  }
}





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

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();
  }
}