基于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);
  }
}

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

相关文章

  • 详解Spring中的拦截器与过滤器

    详解Spring中的拦截器与过滤器

    Filter 过滤器和Interceptor 拦截器是SpringBoot 的 Web 项目开发中长用到的,本文主要来和大家讨论一下 Filter 与 Interceptor 的做法及它们之间的区别,需要的可以参考下
    2023-07-07
  • Prometheus 入门教程之SpringBoot 实现自定义指标监控

    Prometheus 入门教程之SpringBoot 实现自定义指标监控

    这篇文章主要介绍了Prometheus 入门教程之SpringBoot 实现自定义指标监控,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-12-12
  • SpringBoot+Mybatis-plus+shardingsphere实现分库分表的方案

    SpringBoot+Mybatis-plus+shardingsphere实现分库分表的方案

    实现亿级数据量分库分表的项目是一个挑战性很高的任务,下面是一个基于Spring Boot的简单实现方案,感兴趣的朋友一起看看吧
    2024-03-03
  • Spring Cache的使用示例详解

    Spring Cache的使用示例详解

    SpringCache是构建在SpringContext基础上的缓存实现,提供了多种缓存注解,如@Cachable、@CacheEvict、@CachePut等,本文通过实例代码介绍了Spring Cache的使用,感兴趣的朋友一起看看吧
    2025-01-01
  • 整理Java编程中字符串的常用操作方法

    整理Java编程中字符串的常用操作方法

    这篇文章主要介绍了Java编程中字符串的常用操作方法的整理,字符串处理是Java入门学习中的基础知识,需要的朋友可以参考下
    2016-02-02
  • @TableField注解之深入理解与应用方式

    @TableField注解之深入理解与应用方式

    在现代软件开发中,@TableField注解作为MyBatis-Plus中的一个重要特性,用于定义实体类字段与数据库表字段的映射关系,本文详细介绍了@TableField注解的使用场景、属性及其在实际开发中的应用,包括字段名称映射、非数据库字段标识、字段填充策略
    2024-10-10
  • SpringBoot+Mybatis-plus实现分页查询的示例代码

    SpringBoot+Mybatis-plus实现分页查询的示例代码

    本文主要介绍了SpringBoot+Mybatis-plus实现分页查询的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2025-02-02
  • Java实现差分数组的示例详解

    Java实现差分数组的示例详解

    差分数组是由原数组进化而来,值为原数组当前位置值减去上一个位置的值。本文将通过例题详解如何利用Java实现差分数组,需要的可以参考一下
    2022-06-06
  • 为什么rest接口返回json建议采用下划线形式,不要用驼峰

    为什么rest接口返回json建议采用下划线形式,不要用驼峰

    为什么rest接口返回json建议采用下划线形式,不要用驼峰?今天小编就来为大家说明一下原因,还等什么?一起跟随小编过来看看吧
    2020-09-09
  • Springboot如何实现对配置文件中的明文密码加密

    Springboot如何实现对配置文件中的明文密码加密

    这篇文章主要介绍了Springboot如何实现对配置文件中的明文密码加密问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-12-12

最新评论