基于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);
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助。
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语