Bonjour,
Mon problème est le suivant je viens de créer un programme tous fonctionne parfaitement mais voilà quand je click sur mon bouton "stop" qui est censé fermer le programme rien ne se passe.
Le problème est que mon application lance une fonction en boucle jusqu’à que l'utilisateur souhaite y mettre un terme via le bouton "stop". Mais la fonction tournant en boucle empêche l'appuie sur le bouton "stop".
Je ne sais pas du tout comment je pourrais régler mon problème et c'est pour cela que je vous demande de l'aide.

Voici le code de mon application :

Affichage : class SaisiInfo

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
import java.awt.BorderLayout;
import java.awt.EventQueue;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;
 
 
public class SaisiInfo extends JFrame {
 
	private JPanel contentPane;
	private JTextField source;
	private JTextField destination;
	private JTextField timer;
 
	/**
         * Launch the application.
         */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SaisiInfo frame = new SaisiInfo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
         * Create the frame.
         */
	public SaisiInfo() {
		setTitle("Timer Folder");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
 
		JLabel lblNewLabel = new JLabel("Adresse du dossier source");
		lblNewLabel.setBounds(20, 51, 159, 14);
		contentPane.add(lblNewLabel);
 
		source = new JTextField();
		source.setText("C:\\...");
		source.setBounds(189, 48, 216, 20);
		contentPane.add(source);
		source.setColumns(10);
 
		JLabel lblAdresseDestination = new JLabel("Adresse du dossier de destination");
		lblAdresseDestination.setBounds(20, 100, 162, 14);
		contentPane.add(lblAdresseDestination);
 
		destination = new JTextField();
		destination.setToolTipText("");
		destination.setText("C:\\...");
		destination.setBounds(189, 97, 216, 20);
		contentPane.add(destination);
		destination.setColumns(10);
 
		JButton btnStart = new JButton("START");
		btnStart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (source.getText()!=null && destination.getText()!=null && timer.getText()!=null){
					String src= source.getText();
					String dst= destination.getText();
					int time= (Integer.parseInt(timer.getText())*1000);			
					try {
						Appli start = new Appli(src, dst, time);
					} catch (IOException | InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
 
			}
		});
		btnStart.setBounds(201, 192, 111, 23);
		contentPane.add(btnStart);
 
		JButton btnStop = new JButton("STOP");
		btnStop.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		btnStop.setBounds(322, 192, 66, 23);
		contentPane.add(btnStop);
 
		JLabel lblTempsDattente = new JLabel("Temps d'attente (secondes)");
		lblTempsDattente.setBounds(20, 152, 159, 14);
		contentPane.add(lblTempsDattente);
 
		timer = new JTextField();
		timer.setBounds(189, 149, 75, 20);
		contentPane.add(timer);
		timer.setColumns(10);
 
		JLabel lblS = new JLabel("s");
		lblS.setBounds(266, 152, 46, 14);
		contentPane.add(lblS);
	}
 
}
Application : class appli

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
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 
 
public class Appli { 
 
	public Appli(String src, String dst, int Timer) throws IOException, InterruptedException { 
 
		File Source= new File(src);
		File Destination= new File(dst);
 
 
		do{
			Thread.sleep(2000);
			if(!emptyDirectory(Source)){
				//System.out.println("Nouveaux fichiers detectes");
				Thread.sleep(Timer);
				copyDirectory(Source , Destination) ; 
				suppr(Source);
				//System.out.println("Fichiers deplaces");
			}
		}while(1>0);
	} 
 
	public static boolean emptyDirectory(File srcDir){ 
		File []liste ;
		boolean resultat=false;
		  if(srcDir.isDirectory())
		  {
		  liste=srcDir.listFiles();
		  if(liste!=null && liste.length==0)
		    {
		    resultat= true; 
		    }
 
		  }
		  return resultat;
		}
 
 
	public static void copyDirectory(File srcDir, File dstDir) throws IOException { 
		if (srcDir.isDirectory()) { 
			if (!dstDir.exists()) { 
				dstDir.mkdir(); 
			} 
			String[] children = srcDir.list(); 
			for (int i = 0; i < children.length; i++) { 
				copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i])); 
			} 
		} else { 
			copyFile(srcDir, dstDir); 
 
 
		} 
	} 
 
	public static void copyFile(File src, File dst) throws IOException { 
		InputStream in = new FileInputStream(src); 
		OutputStream out = new FileOutputStream(dst); 
		byte[] buf = new byte[1024]; 
		int len; 
		while ((len = in.read(buf)) > 0) { 
			out.write(buf, 0, len); 
		} 
		in.close(); 
		out.close(); 
	} 
 
	public static void suppr(File r){
		File [] fileList = r.listFiles();
		for(int i = 0;i<fileList.length;i++){
			if(fileList[i].isDirectory() ){
				suppr(fileList[i]);
				fileList[i].delete();
			}else{
				fileList[i].delete();
			}
		}
	}
 
}
Merci d'avance pour votre aide.