Comment passer argument a une instance Javafx
Bonjour,
Je suis debutant.
J'ai devellopé un appli qui fait des traitement et lance diverses actions.
A cela j'avais decidé d'implementer une IHM via Swing, fenetre, cases a cocher, une console, ce genre de chose.
Avec Swing je faisais une classe Fenetre, que j'appellais avec un argument afin de lui passer mes arguments :
Code:
Fenetre fenetre = new Fenetre(programme);
Puis dans ma fenêtre je pouvais agir sur mon programme de la sorte :
Code:
programme.allumer();
ou du programme aller dans la fenetre :
Code:
programme.fenetre.getCaseOnouOff();
Depuis je veux essayer javafx, même si son avenir est incertain comme j'ai pu le lire ici, peu importe, cest pour apprendre et m'amuser.
Je n'arrive pas a passer de paramètre a la fenêtre :
Même en faisant un Setteur, il ne passe pas la barre du launch() de javaFx.
Le code soumis est peut être pas au point, certes, mais c'est la méthode de passation d'argument qui m'intéresse, je vois bien que le quelque chose m'échappe, et je bloque.
la classe appelante, qui exécute les lancement:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| import java.*;
import java.awt.AWTException;
import java.awt.EventQueue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import javafx.application.Application;
public class LancerP extends Thread {
public static boolean actif = true;
static WebDriver driver;
TachePrice tache;
Fenetre tfenetre;
FxFenetre fxFenetre;
LancerP p;
public void lancerp(LancerP p) {
this.p = p ;
// try {
// tfenetre = new Fenetre(p);
fxFenetre = new FxFenetre();
fxFenetre.main();
fxFenetre.setP(p);
// } catch (IOException e) {System.out.println("IO exeption");}
}
public static void main(String[] args) throws AWTException, IOException {
LancerP pStart = new LancerP();
pStart.lancerp(pStart);
}
public static void arreter(){
actif = false;
}
public WebDriver setDriver(WebDriver driver) {
driver = this.driver;
return driver;
}
public void lancerTachePrice(String url, String nomDeCompte, String motDePasse){
tache = new TachePrice(p, urlr, nomDeCompte, motDePasse);
tache.allume = true;
System.out.println(tache.getName());
System.out.println(tache.getState());
if (!tache.isAlive()){
tachestart();
System.out.println(tache.getName());
System.out.println(tache.getState()); |
class main de javafx
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public class FxFenetre extends Application {
LancerP p;
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("findpage");
FxFenetreController controller = new FxFenetreController();
controller.setLancerP(p);
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("FxFenetre.fxml"));
ScrollPane myPane = (ScrollPane) loader.load();
controller = loader.getController();
Scene myScene = new Scene(myPane);
primaryStage.setScene(myScene);
primaryStage.show();
}
public static void main() {
launch();
}
public void setP(LancerP p){
this.p = p;
} |
le controller javafx
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
public class FxFenetreController extends ScrollPane {
LancerP p;
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private Button boutonOn;
@FXML
private Button boutonOff;
@FXML
private Button bypassPause;
@FXML
private TextField nomDeCompte;
@FXML
private PasswordField motDePasse;
@FXML
private TextField url;
@FXML
void initialize() {
assert boutonOn != null : "fx:id=\"boutonOn\" was not injected: check your FXML file 'fxFenetre.fxml'.";
assert boutonOff != null : "fx:id=\"boutonOff\" was not injected: check your FXML file 'fxFenetre.fxml'.";
assert bypassPause != null : "fx:id=\"bypassPause\" was not injected: check your FXML file 'fxFenetre.fxml'.";
assert nomDeCompte != null : "fx:id=\"nomDeCompte\" was not injected: check your FXML file 'fxFenetre.fxml'.";
assert motDePasse != null : "fx:id=\"motDePasse\" was not injected: check your FXML file 'fxFenetre.fxml'.";
assert url != null : "fx:id=\"url\" was not injected: check your FXML file 'fxFenetre.fxml'.";
}
public void setLancerP(LancerP p) {
this.p = p;}
@FXML
private void boutonOn(){
System.out.println("on");
p.lancerP("http://www.amazon.fr", "login", "mdp");
}
@FXML
private void boutonOff(){ System.out.println("off");}
} |
le fxml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.embed.swing.SwingNode?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<ScrollPane fitToHeight="true" fitToWidth="true" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ppackage.FxFenetreController">
<content>
<BorderPane>
<top>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="NEVER" minWidth="50.0" />
<ColumnConstraints hgrow="NEVER" minWidth="100.0" prefWidth="150.0" />
<ColumnConstraints hgrow="SOMETIMES" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox>
<children>
<Button fx:id="boutonOn" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#boutonOn" text="on" />
<Button fx:id="boutonOff" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#boutonOff" text="off" />
<Button fx:id="bypassPause" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Passer pause" />
</children>
</VBox>
<VBox GridPane.columnIndex="1">
<children>
<TextField fx:id="nomDeCompte" text="" />
<PasswordField fx:id="motDePasse" prefHeight="25.0" prefWidth="96.0" text="" />
<TextField fx:id="" text="" />
</children>
</VBox>
<FlowPane columnHalignment="CENTER" hgap="15.0" rowValignment="TOP" GridPane.columnIndex="2">
<children>
<CheckBox fx:id="a" contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="a">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox fx:id="z" contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="z">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox fx:id="e" contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="e">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="CheckBox">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="CheckBox">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="CheckBox">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
<CheckBox contentDisplay="RIGHT" graphicTextGap="2.0" mnemonicParsing="false" selected="true" text="CheckBox">
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</CheckBox>
</children>
<padding>
<Insets left="5.0" />
</padding>
</FlowPane>
</children>
</GridPane>
</top>
<center>
<TabPane tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Console">
<content>
<SwingNode />
</content>
</Tab>
<Tab text="Parametres" />
<Tab text="Xpath" />
<Tab text="default" />
</tabs>
</TabPane>
</center>
<bottom>
<CheckBox mnemonicParsing="false" selected="true" text="" />
</bottom>
</BorderPane>
</content>
</ScrollPane> |
Si vous aviez une méthode en tete ?
Merci de m'avoir lu.
Nico