Partage
  • Partager sur Facebook
  • Partager sur Twitter

affichage d'un demineur probleme compilation

Sujet résolu
    25 mai 2016 à 16:05:31

    Bonjour a tous ,

    J'essaye de faire un demineur, et je galère à mort avec l'affichage je voulais commencer par faire mon plateau de jeux, je l'ai fais avec scene builder et voici le xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.control.CheckMenuItem?>
    <?import javafx.scene.control.Menu?>
    <?import javafx.scene.control.MenuBar?>
    <?import javafx.scene.control.MenuItem?>
    <?import javafx.scene.layout.AnchorPane?>
    <?import javafx.scene.layout.ColumnConstraints?>
    <?import javafx.scene.layout.GridPane?>
    <?import javafx.scene.layout.Pane?>
    <?import javafx.scene.layout.RowConstraints?>
    
    <fx:root prefHeight="532.0" prefWidth="900.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="vue.Controlleur">
       <children>
          <Pane layoutX="-60.0" prefHeight="689.0" prefWidth="967.0">
             <children>
                <GridPane layoutX="61.0" layoutY="26.0" prefHeight="666.0" prefWidth="907.0">
                  <columnConstraints>
                    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                  </columnConstraints>
                  <rowConstraints>
                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  </rowConstraints>
                </GridPane>
                <MenuBar layoutX="55.0" layoutY="1.0" prefHeight="25.0" prefWidth="913.0">
                  <menus>
                    <Menu mnemonicParsing="false" text="File">
                      <items>
                        <MenuItem mnemonicParsing="false" text="New game" />
                      </items>
                    </Menu>
                    <Menu mnemonicParsing="false" text="Niveaux">
                      <items>
                            <CheckMenuItem mnemonicParsing="false" text="Debutant" />
                      </items>
                    </Menu>
                  </menus>
                </MenuBar>
             </children>
          </Pane>
       </children>
    </fx:root>
    

    j'ai fais 3 package (controlleur vue applicatioin) , mais j'ai mis mon fichier xml avec le controlleur et mon main dans vue (histoire de voir si ça va)

    voici le code du controlleur ( sachant que je veux boucler un bouton dedans pour faire tout mes case) mais bon ça ne marche pas. Mon controlleur sers à faire les utiliser des mon intterface graphique, je voudrais juste l'afficher pour commencer :D voila quand même le code

    package vue;
    
    import javafx.fxml.FXML;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.layout.ColumnConstraints;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.RowConstraints;
    
    public class Controlleur {
    	@FXML
    	private Controlleur cont;
    	@FXML
    	private Button bouton;
    	@FXML
    	private GridPane grid;
    	@FXML
    	private Label result;
    
    	public Controlleur() {
    		{
    		//	if (uniqueInstance == null)uniqueInstance = this; 
    				
    		}
    		
    
    	/*	for (int row = 0; row < 8; row++) {
    			final RowConstraints rowConstraints = new RowConstraints();
    			grid.getRowConstraints().add(rowConstraints);
    		}
    
    		for (int col = 0; col < 8; col++) {
    			final ColumnConstraints columnConstraints = new ColumnConstraints();
    			grid.getColumnConstraints().add(columnConstraints);
    		}
    
    		for (int row = 0; row < 8; row++) {
    			for (int col = 0; col < 8; col++) {
    				Button b = new Button();
    				// ta tambouille sur le bouton : texte, event handlers, etc.
    				// ajout à la grille en position row,col
    				grid.add(b, col, row);
    			}
    		}*/
    
    	}
    }

    et voici le main

    package vue;
    
    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.layout.GridPane;
    
    public class Main extends Application {
    	
    	private GridPane rootLayout;
    
    	private static Main uniqueInstance = null;
    
    	@Override
    	public void start(Stage primaryStage) {
    		try {
    			FXMLLoader loader = new FXMLLoader();
    			loader.setLocation(Main.class.getResource("plateau.fxml"));
    			this.rootLayout = (GridPane) loader.load();
    			Scene scene = new Scene(rootLayout);
    			primaryStage.setScene(scene);
    			primaryStage.show();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void main(String[] args) {
    		launch(args);
    	}
    
    	public Main() {
    		if (uniqueInstance == null) {
    			uniqueInstance = this;
    		}
    	}
    
    	public static Main getInstance() {
    		if (uniqueInstance == null) {
    			uniqueInstance = new Main();
    		}
    		return uniqueInstance;
    	}
    
    	public GridPane getRootLayout() {
    		return rootLayout;
    	}
    
    }

    Quand je compile il me mets toute ces erreur.

    javafx.fxml.LoadException: Root hasn't been set. Use method setRoot() before load.
    /C:/Users/Jean/workspace/ProjetDemineur/bin/vue/plateau.fxml:13
    
    	at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    	at javafx.fxml.FXMLLoader.access$100(Unknown Source)
    	at javafx.fxml.FXMLLoader$RootElement.constructValue(Unknown Source)
    	at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
    	at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
    	at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    	at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    	at javafx.fxml.FXMLLoader.load(Unknown Source)
    	at vue.Main.start(Main.java:20)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    	at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    	at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    

    Je me sers d'un exemple ou il n'y as pas de setRoot(), et d'ailleur je sais même pas comment l'utiliser :D

    fin voila merci , bon journée à tous




    -
    Edité par Don_raftapss 25 mai 2016 à 16:09:12

    • Partager sur Facebook
    • Partager sur Twitter
      3 décembre 2017 à 5:42:43

      S'il vous plaît j'aime avoir une aide sur ce Problème de warning avec  JavaFX8 (Root hasn't been set. Use method setRoot() before load.)

      En effet il y a écris résolus et pourtant il n'y a pas la solution donnée.

      Merci d'avance

      -
      Edité par williamss 3 décembre 2017 à 5:52:54

      • Partager sur Facebook
      • Partager sur Twitter

      affichage d'un demineur probleme compilation

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown