基于socket和javaFX简单文件传输工具
作者:uncle_zhang 发布时间:2022-11-04 12:37:42
标签: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);
}
}
0
投稿
猜你喜欢
- 说明本项目采用 maven 结构,主要演示了 spring mvc + mybatis,controller 获取数据后以json 格式返回
- 完成一个简单的基于MVC的数据查询模块,要求能够按照name进行模糊查询。Index.jsp:<%@ page import=&quo
- 这是Hadoop学习全程记录第1篇,在这篇里我将介绍一下如何在Linux下安装Hadoop1.x。先说明一下我的开发环境:虚拟机:VMwar
- Java包装类基本类型大小包装器类型boolean/Booleanchar16bitBooleanbyte8bitByteshort/16b
- utf-8转unicode public static String utf8ToUnicode(String inStr) {  
- 1.CAS1)CAS概念CAS时Compare And Swap缩写,即比较与交换是用于实现多线程同步的原子指令,它将内存位置的内容与给定值
- 一、Javassist入门(一)Javassist是什么Javassist是可以动态编辑Java字节码的类库。它可以在Java程序运行时定义
- 这一篇博客我们来使用UGUI实现图片的拖拽功能。说到拖拽,那必然离不开坐标,UGUI 的坐标有点不一样,它有两种坐标,一种是屏幕坐标,还有一
- 一、Spring Boot 、 Spring MVC 、Spring对比首先你需要明白一件事情:Spring Boot项目目的并不是替换Sp
- 这篇文章主要介绍了SpringBoot文件访问映射如何实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要
- 先上效果图这个效果来自于三星S5的充电界面,当然有些细节差别,主要看思路.本文目的是技术交流,不要将效果直接运用于商业产品和项目.电池背景因
- 方法一:使用多个controller的共同拥有的父类,即精确到两个controller的上一级@Beanpublic Docket crea
- static :静态常量,静态方法,静态代码块静态变量: 静态变量属于类的,使用类名来访问,非静态变量是属于对象的,"必须&quo
- 前言这几天同事跟我在升级Android target SDK和build tool版本的时候,碰到了一个非常搞笑的问题,基本可以算作是“坑”
- SpringBoot切面拦截@PathVariable参数及抛出异常的全局处理微信小程序的接口验证防止非法请求,登录的时候获取openId生
- 一、前沿如果你学习过其他的编程语言,你就会发现 Java 的语法很是哆嗦,可是我们为什么没有放弃 Java 这门编程语言呢?因为 JVM 是
- private void button1_Click(object sender, EventArgs e) {
- 问:怎样才能将XML文件导入SQL Server 2000? 答:将XML文件导入SQL Server有若干种方法,这里提供其中的3种: 大
- import java.util.List;/*** * 基本接口 * * @author xyq 
- 五子棋游戏(Java),供大家参考,具体内容如下思路:1.首先创建一个棋盘,建立一个二维数组,此文中为一个15*15的二维数组,2.初始化棋