基于socket和javaFX簡單文件傳輸工具
更新時間:2016年02月10日 21:21:35 作者:uncle_zhang
這篇文章主要介紹了基于socket和javaFX簡單文件傳輸工具的相關資料,需要的朋友可以參考下
本文實例介紹了基于socket和javaFX簡單文件傳輸工具,分享給大家供大家參考,具體內容如下
package application;
import java.io.File;
import org.james.component.ButtonBox;
import org.james.component.FileReceiverGrid;
import org.james.component.FileSenderGrid;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class Main extends Application {
public static Stage primaryStage;
@Override
public void start(Stage primaryStage) {
try {
this.primaryStage = primaryStage;
primaryStage.setFullScreen(false);
primaryStage.setResizable(false);
FileReceiverGrid fileReceiverGrid = new FileReceiverGrid();
fileReceiverGrid.initialize();
FileSenderGrid fileSenderGrid = new FileSenderGrid();
fileSenderGrid.initialize();
ButtonBox buttonBox = new ButtonBox();
buttonBox.initialize();
BorderPane root = new BorderPane();
root.setTop(fileReceiverGrid);
root.setBottom(buttonBox);
buttonBox.getReceiveFileFunc().setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
buttonBox.getReceiveFileFunc().setDisable(true);
buttonBox.getSendFileFunc().setDisable(false);
root.setTop(fileReceiverGrid);
}
});
buttonBox.getSendFileFunc().setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
buttonBox.getReceiveFileFunc().setDisable(false);
buttonBox.getSendFileFunc().setDisable(true);
root.setTop(fileSenderGrid);
}
});
fileSenderGrid.getSelectFileBtn().setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("打開文件");
File selectedFile = fileChooser.showOpenDialog(primaryStage);
if(selectedFile != null){
fileSenderGrid.setFile(selectedFile);
fileSenderGrid.getFileNameLabel().setText(selectedFile.getPath());
}
}
});
Scene scene = new Scene(root,800,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
以上就是本文的全部內容,希望對大家的學習有所幫助。
相關文章
Prometheus 入門教程之SpringBoot 實現自定義指標監(jiān)控
這篇文章主要介紹了Prometheus 入門教程之SpringBoot 實現自定義指標監(jiān)控,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12
SpringBoot+Mybatis-plus+shardingsphere實現分庫分表的方案
實現億級數據量分庫分表的項目是一個挑戰(zhàn)性很高的任務,下面是一個基于Spring Boot的簡單實現方案,感興趣的朋友一起看看吧2024-03-03
SpringBoot+Mybatis-plus實現分頁查詢的示例代碼
本文主要介紹了SpringBoot+Mybatis-plus實現分頁查詢的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2025-02-02
為什么rest接口返回json建議采用下劃線形式,不要用駝峰
為什么rest接口返回json建議采用下劃線形式,不要用駝峰?今天小編就來為大家說明一下原因,還等什么?一起跟隨小編過來看看吧2020-09-09

