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.