基于socket和javaFX簡(jiǎn)單文件傳輸工具
本文實(shí)例介紹了基于socket和javaFX簡(jiǎn)單文件傳輸工具,分享給大家供大家參考,具體內(nèi)容如下
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("打開(kāi)文件"); 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); } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
java URL 獲取PHP JSON 數(shù)據(jù)
這篇文章主要介紹了java URL 獲取PHP JSON 數(shù)據(jù),需要的朋友可以參考下2016-04-04老生常談Java?網(wǎng)絡(luò)編程?——?Socket?詳解
這篇文章主要介紹了Java?網(wǎng)絡(luò)編程?——?Socket?相關(guān)知識(shí),本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-05-05Java獲取任意http網(wǎng)頁(yè)源代碼的方法
這篇文章主要介紹了Java獲取任意http網(wǎng)頁(yè)源代碼的方法,可實(shí)現(xiàn)獲取網(wǎng)頁(yè)代碼以及去除HTML標(biāo)簽的代碼功能,涉及Java正則操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-09-09解析Oracle數(shù)據(jù)庫(kù)中的對(duì)象集合schema
這篇文章主要介紹了Oracle數(shù)據(jù)庫(kù)中的對(duì)象集合schema,是Oracle數(shù)據(jù)庫(kù)入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-11-11Spring Boot整合web層實(shí)現(xiàn)過(guò)程詳解
這篇文章主要介紹了Spring Boot整合web層實(shí)現(xiàn)過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04Maven項(xiàng)目打包成可執(zhí)行Jar文件步驟解析
這篇文章主要介紹了Maven項(xiàng)目如何打包成可執(zhí)行Jar文件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05