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
|
private void copyFile() { // fonction qui copie le fichier sur le serveur
Thread trd = new Thread() {
FTPConnection connection = new FTPConnection();
public void run() {
try {
if (connection.connect("127.0.0.1")) {
if (connection.login("toto", "toto")) {
connection.uploadFile(selected_file.getName(), addSlashes(selected_file.getPath()));
// Upload du fichier qui dure un certain temps
try {
Thread.sleep(500); // Pause du thread
}
catch (InterruptedException e) {
}
}
}
connection.disconnect();
}
catch(UnknownHostException e) {
}
catch(IOException e) {
}
}
};
trd.start();
while(trd.isAlive()) { // Quand il upload, je vérifie la taille du fichier sur le serveur. Cette fonction fonctionne correctement à intervalle régulier.
FTPConnection connection2 = new FTPConnection();
try {
if (connection2.connect("127.0.0.1")) {
if (connection2.login("toto2", "toto2")) {
loaded = (int)(connection2.getFileSize(selected_file.getName())*100/selected_file.length());
// Update de la barre de progression, qui ne marche pas !!!
Runnable updateBar = new Runnable() {
public void run() {
bar.setString("Progression " + loaded + "%");
bar.setStringPainted(true);
bar.setValue(loaded);
cp.validate();
}
};
SwingUtilities.invokeLater(updateBar); // Que faire?
}
}
connection2.disconnect();
}
catch(UnknownHostException e) {
}
catch(IOException e) {
}
}
} |
Partager