Bonjour,
Mon application n'arrive pas à quitter proprement, j'utilises juste swt.jar et l'environnement est sous linux (Debian et même problème sous Ubuntu)
Ci dessous 2 fichiers de l'application : le main et le composite de quitter.
Au System.exit(0), il ne fait rien, ai-je oublier quelque chose ou la méthode n'est pas bonne ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fullscreen; import java.io.IOException; import openflyers.MAJBoiteAcle; import openflyers.Serveur2; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import config.FileProperties; public class Main { private Shell shell; private Display display; private Thread t; private Composite composite; private Quitter quitter; private Journaux journaux; private StackLayout stackLayout; private static final boolean AFFICHER_CLAVIER = false; public static int LARGEUR_ECRAN = 1100; public static int HAUTEUR_ECRAN = 800; protected static boolean AUTHENTICATED = false; private static final boolean UTILISER_PLEIN_ECRAN = false; private Serveur2 serveur; private boolean pleinEcran; private void createContents(GridData fillData) { ToolItem menuQuitter = new ToolItem(toolBar, SWT.FLAT | SWT.RIGHT_TO_LEFT); menuQuitter.setText("Quitter"); menuQuitter.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if(pleinEcran && UTILISER_PLEIN_ECRAN) { quitterPleineEcran(); } authentification.setCompositeVerouiller(quitter.getComposite()); if(AUTHENTICATED) { System.exit(0); } else { authentification.clearText(); stackLayout.topControl = authentification.getComposite(); composite.layout(); } } }); stackLayout.topControl = quitter.getComposite(); composite.layout(); } public void quitterPleineEcran() { pleinEcran = false; if(shell!=null) { shell.dispose(); } shell = new Shell(display); System.out.println("[fullscreen.Main] Largeur ecran : "+shell.getSize().x); System.out.println("[fullscreen.Main] hauteur ecran : "+shell.getSize().y); shell.setMaximized(true); shell.setLayout(new GridLayout()); composite = new Composite(shell, SWT.NONE); GridData fillData = new GridData(SWT.FILL, SWT.FILL, true, true); stackLayout = new StackLayout(); composite.setLayout(stackLayout); composite.setLayoutData(fillData); createContents(fillData); quitter.setThread(t); quitter.setServeur(serveur); shell.setMaximized(true); shell.setText("OpenFlyers"); try { shell.open(); shell.layout(); try { while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } finally { if (!shell.isDisposed()) { shell.dispose(); } } } finally { display.dispose(); } System.out.println("Kioko"); //System.exit(0); } public void run() { display = new Display(); pleinEcran = true; if(UTILISER_PLEIN_ECRAN) { pleineEcran(); } else { quitterPleineEcran(); } } public static void main(String[] args) throws Exception { Main main = new Main(); main.run(); System.out.println("ICI"); System.exit(0); } }
Le deuxième fichier :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93 package fullscreen; import openflyers.Serveur2; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; public class Quitter { private Composite compositeQuitter; private Thread t; private Serveur2 serveur; public Quitter(Composite parent, int width, int height, final Shell shell, final Display display, final Thread t, final Serveur2 serveur) { GridLayout layout = new GridLayout(); layout.numColumns = 1; compositeQuitter = new Composite(parent, SWT.NONE); compositeQuitter.setLayout(layout); compositeQuitter.setSize(width, height); GridData gridData = new GridData(SWT.CENTER, SWT.BOTTOM, true, true, 1, 1); gridData.widthHint = width; Label intitule = new Label(compositeQuitter, SWT.CENTER); intitule.setText("Voulez-vous quitter ?"); intitule.setLayoutData(gridData); gridData = new GridData(SWT.CENTER, SWT.TOP, true, true, 1, 1); Button oui = new Button(compositeQuitter, SWT.NONE); oui.setText("Oui"); gridData.widthHint = width/2; oui.setLayoutData(gridData); oui.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { // display.dispose(); // shell.dispose(); // System.exit(0); exit(display, shell); } }); compositeQuitter.layout(); } public void setVisible(boolean visible) { compositeQuitter.setVisible(visible); } public Composite getComposite() { return compositeQuitter; } public void setThread(Thread thread) { this.t = thread; } public void setServeur(Serveur2 serveur) { this.serveur = serveur; } public void exit(Display display, Shell shell) { //display.dispose(); shell.dispose(); //serveur.close(); //Thread thread = Thread.currentThread(); //thread.interrupt(); //t.interrupt(); // Runtime.getRuntime().runFinalizersOnExit(true); // System.exit(0); System.runFinalization(); //Runtime.getRuntime().runFinalization(); // Runtime.getRuntime().exit(0); // Runtime.getRuntime().halt(1); System.out.println("Raaaaaah"); //System.exit(0); } }
Partager