-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathErrorBoxGUI.java
80 lines (70 loc) · 1.79 KB
/
ErrorBoxGUI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package Client;
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 ErrorBoxGUI {
String errorMessage;
Display display;
Shell shell = new Shell(display);
public ErrorBoxGUI(String errorMessage){
this.errorMessage = errorMessage;
}
public void open() {
new Thread(new Runnable() {
public void run() {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try{
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}catch(Exception e){
e.printStackTrace();
}
}
});
}
}).start();
}
public void close(){
shell.close();
}
protected void createContents() {
display = Display.getDefault();
int style = SWT.ICON_ERROR;
//SWT.ICON_QUESTION | SWT.YES | SWT.NO
MessageBox messageBox = new MessageBox(shell, style);
messageBox.setMessage(errorMessage);
int rc = messageBox.open();
switch (rc) {
case SWT.OK:
System.out.println("SWT.OK");
break;
case SWT.CANCEL:
System.out.println("SWT.CANCEL");
break;
case SWT.YES:
System.out.println("SWT.YES");
break;
case SWT.NO:
System.out.println("SWT.NO");
break;
case SWT.RETRY:
System.out.println("SWT.RETRY");
break;
case SWT.ABORT:
System.out.println("SWT.ABORT");
break;
case SWT.IGNORE:
System.out.println("SWT.IGNORE");
break;
}
close();
}
}