欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-09 10:26:17
本文实例介绍了基于socket和javafx简单文件传输工具,分享给大家供大家参考,具体内容如下 package application; impor...

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

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