基于socket和javaFX简单文件传输工具
本文实例介绍了基于socket和javaFX简单文件传输工具,分享给大家供大家参考,具体内容如下
packageapplication; importjava.io.File; importorg.james.component.ButtonBox; importorg.james.component.FileReceiverGrid; importorg.james.component.FileSenderGrid; importjavafx.application.Application; importjavafx.event.ActionEvent; importjavafx.event.EventHandler; importjavafx.scene.Scene; importjavafx.scene.layout.BorderPane; importjavafx.stage.FileChooser; importjavafx.stage.Stage; publicclassMainextendsApplication{ publicstaticStageprimaryStage; @Override publicvoidstart(StageprimaryStage){ try{ this.primaryStage=primaryStage; primaryStage.setFullScreen(false); primaryStage.setResizable(false); FileReceiverGridfileReceiverGrid=newFileReceiverGrid(); fileReceiverGrid.initialize(); FileSenderGridfileSenderGrid=newFileSenderGrid(); fileSenderGrid.initialize(); ButtonBoxbuttonBox=newButtonBox(); buttonBox.initialize(); BorderPaneroot=newBorderPane(); root.setTop(fileReceiverGrid); root.setBottom(buttonBox); buttonBox.getReceiveFileFunc().setOnAction(newEventHandler<ActionEvent>(){ @Override publicvoidhandle(ActionEventevent){ buttonBox.getReceiveFileFunc().setDisable(true); buttonBox.getSendFileFunc().setDisable(false); root.setTop(fileReceiverGrid); } }); buttonBox.getSendFileFunc().setOnAction(newEventHandler<ActionEvent>(){ @Override publicvoidhandle(ActionEventevent){ buttonBox.getReceiveFileFunc().setDisable(false); buttonBox.getSendFileFunc().setDisable(true); root.setTop(fileSenderGrid); } }); fileSenderGrid.getSelectFileBtn().setOnAction(newEventHandler<ActionEvent>(){ @Override publicvoidhandle(ActionEventevent){ FileChooserfileChooser=newFileChooser(); fileChooser.setTitle("打开文件"); FileselectedFile=fileChooser.showOpenDialog(primaryStage); if(selectedFile!=null){ fileSenderGrid.setFile(selectedFile); fileSenderGrid.getFileNameLabel().setText(selectedFile.getPath()); } } }); Scenescene=newScene(root,800,400); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); }catch(Exceptione){ e.printStackTrace(); } } publicstaticvoidmain(String[]args){ launch(args); } }
以上就是本文的全部内容,希望对大家的学习有所帮助。