Este artículo presenta una herramienta de transferencia de archivos simple basada en Socket y Javafx. Se comparte con usted para su referencia. El contenido específico es el siguiente
aplicación de paquete; import java.io.file; importar org.james.component.Buttonbox; import org.james.component.filereceiverGrid; import org.james.component.filesSerGrid; import javafx.application.application; import javafx.event.actionEvent; import javafx.event.eventhandler; import javafx.scene.scene.scene.scene.scene.scene.scene; javafx.scene.layout.borderpane; import javafx.stage.filechooser; import javafx.stage.stage; Public Class Main extiende la aplicación {Public Static Stage PrimaryStage; @Override public void Start (Stage PrimaryStage) {try {this.PrimaryStage = primario; PrimaryStage.SetFullScreen (falso); PrimaryStage.SetResizable (falso); FilereceReiverGrid filereceiverGrid = new FileReCeiverGrid (); FilerEceiverGrid.initialize (); FileSenderGrid filsenderGrid = new FilesSerGrid (); filsenderGrid.initialize (); Buttonbox Buttonbox = new Buttonbox (); Buttonbox.initialize (); BorderPane root = new BorderPane (); root.settop (FilereceiverGrid); root.setBottom (Buttonbox); buttonbox.getReceiveFileFunc (). SetOnAction (new EventHandler <CtionEvent> () {@Override public Void Handle (ActionEvent Event) {ButtonBox.getReceiveFileFunc (). SetDisable (true); ButtonBox.getSendFunceFunc (). SetDisable (falso); root.settop (filerECECeVeVergrid;});}); Buttonbox.getSendFileFunc (). SetOnaction (nuevo EventHandler <CtionEvent> () {@Override public Void Handle (ActionEvent Event) {ButtonBox.GetReceiveFileFunc (). SetDisable (false); ButtonBox.getSendFileFunc (). SetDisable (true); root.settop (filsenderGrid);}}); filesSenderGrid.getSelectFileBtn (). SetOnAction (new EventHandler <CtionEvent> () {@Override public void Handle (ActionEvent Event) {fileChooser fileChooser = new FileChooser (); fileChooser.settitle ("Archivo abierto"); File SelectFile = FileChooser.ShowOpenDialog (Primarystage (Primarystage (Primaryfile); NULL) {filsenderGrid.setFile (selectedFile); Escena escena = nueva escena (raíz, 800,400); escena.getstylesheets (). add (getClass (). getResource ("Application.css"). ToExternalForm ()); PrimaryStage.Setscene (escena); PrimaryStage.Show (); } catch (Exception e) {E.PrintStackTrace (); }} public static void main (string [] args) {lanzamiento (args); }}Lo anterior se trata de este artículo, espero que sea útil para el aprendizaje de todos.