javafx kullanarak bir masaüstü uygulaması yapıyordum. benim fxml dosyasıdır: - indirme düğmesi içinProgressBar javafx ile tegerring değil
<?import java.lang.String?>
<?import javafx.collections.FXCollections?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.Buildsapp.Main.BuildsController" fx:id="ap">
<children>
<HBox alignment="CENTER_LEFT" layoutX="6.0" layoutY="14.0" spacing="20.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<ComboBox fx:id="versionCombo" prefHeight="31.0" prefWidth="108.0" promptText="7.0 Win">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Win" />
<String fx:value="Mac" />
</FXCollections>
</items>
<value>
<String fx:value="Win" />
</value>
</ComboBox>
<ComboBox fx:id="versionNo" prefHeight="31.0" prefWidth="89.0" promptText="7.0" />
<Button fx:id="downloadButton" minWidth="80.0" mnemonicParsing="false" text="Download" />
<Button fx:id="installButton" minWidth="80.0" mnemonicParsing="false" text="Install" />
<ComboBox fx:id="locCombo" prefHeight="31.0" prefWidth="103.0">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="CJ" />
<String fx:value="MN" />
</FXCollections>
</items>
<value>
<String fx:value="CJ" />
</value>
</ComboBox>
<ProgressBar fx:id="progressBar1" prefHeight="23.0" prefWidth="102.0" progress="0.0" />
</children>
<padding>
<Insets left="10.0" right="3.0" top="5.0" />
</padding>
</HBox>
<TableView fx:id="tableView" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="2.0" AnchorPane.rightAnchor="2.0" AnchorPane.topAnchor="40.0">
<columns>
<TableColumn fx:id="builds" prefWidth="482.0" text="Builds" />
<TableColumn fx:id="date" minWidth="0.0" prefWidth="124.0" text="Date" />
<TableColumn fx:id="release" prefWidth="168.0" text="Release" />
</columns>
</TableView>
</children>
</AnchorPane>
benim denetleyicisi sınıftır: - aşağıdaki gibi
downloadButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
download();
}
});
indirme yöntemidir.
private void download() {
FTPClient ftpClient = new FTPConnection().makeConnection(loc);
try {
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
success = ftpClient.changeWorkingDirectory(PATH + preset + "/" + file_to_download + offset);
System.out.println("Download Path:-" + PATH + preset + "/" + file_to_download + offset);
if (!success) {
System.out.println("Could not changed the directory to RIBS");
return;
} else {
System.out.println("Directory changed to RIBS");
}
FTPFile[] files = ftpClient.listFiles();
for (FTPFile file : files) {
if (file.getName().contains(".zip")) {
dfile = file.getName();
}
}
fileMap.put("build", dfile);
primaryStage = (Stage) ap.getScene().getWindow();
String homePath = System.getProperty("user.home");
File downloadPath = new File(homePath + "\\LightroomBuildss\\" + osVer);
if (!downloadPath.exists()) {
if (downloadPath.mkdirs()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
}
// System.out.println(chosenDir.getAbsolutePath());
filePath = new File(downloadPath + "/" + dfile);
if (filePath.exists()) {
System.out.println("File altready exist");
return;
} else {
fileMap.put("path", filePath.toString());
fileMap.put("kind", "RIBS");
Task task = new Task<Void>() {
@Override
public Void call() throws IOException {
try {
output = new FileOutputStream(downloadPath + "/" + dfile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ftpClient.sendNoOp();
ftpClient.setConnectTimeout(1000);
Task<Void> sleeper = new Task<Void>() {
@Override
protected Void call() throws Exception {
try {
for (double progress = 0.0; progress < 100.0; progress++) {
Thread.sleep(100);
updateProgress(progress, 100);
System.out.println(progress);
}
} catch (InterruptedException e) {
}
return null;
}
};
ProgressBar slider = startProgressBar();
slider.progressProperty().bind(sleeper.progressProperty());
Thread thread = new Thread(sleeper);
thread.start();
if (ftpClient.retrieveFile(dfile, output) == true) {
downloadButton.setDisable(true);
outsize = dfile.length();
}
return null;
}
};
Thread t = new Thread(task);
t.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
benim ilerleme çubuğu kodu: -
public ProgressBar startProgressBar() {
Stage primaryStage = new Stage();
ProgressBar pb = new ProgressBar(0);
ProgressIndicator pi = new ProgressIndicator(0);
pi.progressProperty().bind(pb.progressProperty());
HBox hb = new HBox();
hb.setSpacing(5);
hb.setAlignment(Pos.CENTER);
hb.getChildren().addAll(pb, pi);
Scene scene = new Scene(hb, 300, 100);
primaryStage.setScene(scene);
primaryStage.show();
return pb;
}
indirme başlar ama yöntemi çağrıldıktan sonra ilerleme çubuğu başlayıp gelmez önce indirme yönteminde gelen startProgessBar yöntemini arıyorum Yöntem çağrısından sonra yazılan kod (bu durumda indirme düğmesinin devre dışı bırakılması), dosyalar gerekli klasöre indirilse de idam edilmez. StartProgressBar yöntemi, düzgün çalıştıktan sonra kod çağrılmıyorsa.
Kodumu söz konusu olarak güncelledim ancak hala ilerleme çubuğunu başlatamıyorum. – user3649361
Şimdi, bir görevin içinde bir görev var, gitmek istediğin gibi bir şey olduğunu düşünmüyorum. Ayrıca, dışarıdaki görev içindeki ilerleme çubuğunu tanımladığınıza benziyorsunuz, ki bunu yapmakta olduğunuz ekrana koymaya çalıştığınızda "Not FXAT" hatası veriyorsunuz. Örneğime bakarsanız, ekran ayarının, görev tanımının dışında, düğmenin olay işleyicisinde - FXAT üzerinde yürütüldüğünü görürsünüz, o zaman bu kod, görevin ilerleme özelliğini bağlar. ilerleme çubuğu. – DaveB
Sahip olacağınız en büyük sorun, FTP istemcisinin (Apache sürümünü kullanıyorsanız) dosya aktarımında herhangi bir ilerleme göstergesinin bulunmamasıdır. Bu yüzden, dosya ilerlemesini kendiniz izlemek için çok iş parçacıklı bir yol bulmak zorundasınız. Dosya boyutunun önce ftp istemcisinden alınması anlamına geleceğinden şüphelenirim; daha sonra, boyut için yerel dosya sisteminde hedef dosyayı izleyen ve buna göre görev ilerleme özelliğini güncelleyen ikinci bir iş parçacığı başlatılır. Sonra dosya indirme işlemini başlatın ve tamamlandığında monitör iş parçacığını öldürün. Başka bir görev değil, ikinci iş parçacığı el ile yapın. – DaveB