Simple File Transfer tool based on socket and JavaFX _java

Source: Internet
Author: User

This example introduces a simple File transfer tool based on sockets and JavaFX, which is shared for everyone to refer to, as follows

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 H
          Andle (ActionEvent event) {Buttonbox.getreceivefilefunc (). Setdisable (True);
          Buttonbox.getsendfilefunc (). Setdisable (false);
        Root.settop (Filereceivergrid);
       
      }
      }); Buttonbox.getsendfilefunc (). Setonaction (New eventhandler<actionevent> () {@Override public void hand
          Le (ActionEvent event) {Buttonbox.getreceivefilefunc (). Setdisable (false);
          Buttonbox.getsendfilefunc (). Setdisable (True);
        Root.settop (Filesendergrid);
       
      } 
      }); FILESENDERGRID.GETSELECTFILEBTN (). Setonaction (New eventhandler<actionevent> () {@Override public voi
          D Handle (ActionEvent event) {Filechooser Filechooser = new Filechooser (); FileChooser.settitle ("Open file");
          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); }
}

The above is the entire content of this article, I hope to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.