基于socket和javaFX简单文件传输工具

所属分类: 软件编程 / java 阅读数: 51
收藏 0 赞 0 分享

本文实例介绍了基于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);
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助。

更多精彩内容其他人还在看

JavaWeb项目部署到服务器详细步骤详解

这篇文章主要介绍了JavaWeb项目如何部署到服务器,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

IDEA基于支付宝小程序搭建springboot项目的详细步骤

这篇文章主要介绍了IDEA基于支付宝小程序搭建springboot项目的详细步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

详解SpringBoot应用服务启动与安全终止

这篇文章主要介绍了SpringBoot应用服务启动与安全终止,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Spring Boot启动及退出加载项的方法

这篇文章主要介绍了Spring Boot启动及退出加载项的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Spring Data Jpa 自动生成表结构的方法示例

这篇文章主要介绍了Spring Data Jpa 自动生成表结构的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

IDEA中osgi的开发应用指南详解

这篇文章主要介绍了IDEA中osgi的开发应用指南详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

详解用maven将dubbo工程打成jar包运行

这篇文章主要介绍了详解用maven将dubbo工程打成jar包运行,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

详解Java合并数组的两种实现方式

这篇文章主要介绍了Java合并数组的两种实现方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

使用Jenkins Pipeline自动化构建发布Java项目的方法

这篇文章主要介绍了使用Jenkins Pipeline自动化构建发布Java项目的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

使用Maven配置Spring的方法步骤

这篇文章主要介绍了使用Maven配置Spring的方法步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享
查看更多