2016-03-19 12 views
0

Zur weiteren Bearbeitung meiner Frage entwickle ich in JavaFX eine Fragenbank. Auf dem Startbildschirm möchte ich die Navigation basierend auf der Auswahl der Radiobuttons innerhalb eines Tastenklicks bereitstellen.Wie ändert man die Bildschirme in javafx beim Erkennen der Radiobutton-Auswahl in einem Buttonclick-Listener?

z.B. Wenn ich eine Radiobutton-Auswahl auswähle und auf die Schaltfläche klicke, um weiterzumachen, sollte sie mich zu der von mir erstellten FXML-Bildschirmdatei führen. Um weiter zu erklären, was ich zu bleiben versuche, ist unten der GUI-Snapshot.

Question Bank GUI Link

ich meinen Code bin Einfügen unter:

Haupthomescreen FXML Datei:

<?xml version="1.0" encoding="UTF-8"?> 

<?import java.lang.*?> 


<?import java.net.*?> 
<?import java.util.*?> 
<?import javafx.scene.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.text.*?> 

<AnchorPane id="AnchorPane" prefHeight="548.0" prefWidth="721.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="controller.HomefxmlController"> 
    <children> 
    <GridPane alignment="CENTER" gridLinesVisible="false" layoutX="210.0" layoutY="149.0" prefHeight="171.0" prefWidth="373.0" visible="true"> 
     <children> 
     <RadioButton fx:id="radioBlanks" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#onRadioBlankClick" text="Fill in the Blank" GridPane.columnIndex="0" GridPane.halignment="LEFT" GridPane.rowIndex="0" GridPane.valignment="CENTER" /> 
     <RadioButton fx:id="radioMcq" mnemonicParsing="false" onAction="#onRadioMcqClick" text="MCQ" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="0" /> 
     <RadioButton fx:id="radioshortNote" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#onRadioSNclick" text="ShortNote" GridPane.columnIndex="0" GridPane.halignment="LEFT" GridPane.rowIndex="1" /> 
     <RadioButton fx:id="radioLongAnswer" mnemonicParsing="false" onAction="#onRadioLNclick" text="LongAnswer" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="1" /> 
     <RadioButton fx:id="radioScenario" mnemonicParsing="false" onAction="#onRadioScenariocClick" text="Scenario" GridPane.columnIndex="0" GridPane.halignment="LEFT" GridPane.rowIndex="2" /> 
     <RadioButton fx:id="radioTF" mnemonicParsing="false" onAction="#onRadioTFclick" text="True/False" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2" /> 
     </children> 
     <columnConstraints> 
     <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> 
    </GridPane> 
    <Label alignment="CENTER" layoutX="234.0" layoutY="47.0" prefHeight="73.0" prefWidth="211.0" text="Question Bank" textAlignment="CENTER" underline="true" wrapText="false"> 
     <font> 
     <Font name="Chiller" size="35.0" /> 
     </font> 
    </Label> 
    <Button fx:id="btnProceed" layoutX="275.0" layoutY="378.0" mnemonicParsing="false" onAction="#onBtntProceed" prefHeight="48.0" prefWidth="129.0" text="Proceed" textFill="#252285"> 
     <font> 
     <Font name="Linux Libertine G Regular" size="20.0" /> 
     </font> 
    </Button> 
    </children> 
    <stylesheets> 
    <URL value="@homefxml.css" /> 
    </stylesheets> 
</AnchorPane> 

FXML Controller-Datei:

package controller; 

import java.io.IOException; 
import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.event.ActionEvent; 
import javafx.fxml.FXML; 
import javafx.fxml.FXMLLoader; 
import javafx.fxml.Initializable; 
import javafx.scene.Parent; 
import javafx.scene.control.Button; 
import javafx.scene.control.RadioButton; 
import javafx.scene.control.ToggleGroup; 
import javafx.stage.Stage; 

/** 
* FXML Controller class 
* 
* @author Vishal 
*/ 
public class HomefxmlController implements Initializable { 

    @FXML 
    private RadioButton radioBlanks; 
    @FXML 
    private RadioButton radioMcq; 
    @FXML 
    private RadioButton radioshortNote; 
    @FXML 
    private RadioButton radioLongAnswer; 
    @FXML 
    private RadioButton radioScenario; 
    @FXML 
    private RadioButton radioTF; 
    @FXML 
    private Button btnProceed; 

    ToggleGroup group; 

    /** 
    * Initializes the controller class. 
    */ 
    @Override 
    public void initialize(URL url, ResourceBundle rb) { 
     // TODO 
     toggleGroupAssign(); 

    } 

    public void toggleGroupAssign() { 
     group = new ToggleGroup(); 
     radioBlanks.setToggleGroup(group); 
     radioMcq.setToggleGroup(group); 
     radioshortNote.setToggleGroup(group); 
     radioLongAnswer.setToggleGroup(group); 
     radioScenario.setToggleGroup(group); 
     radioTF.setToggleGroup(group); 
    } 

    @FXML 
    private void onBtntProceed(ActionEvent event) throws IOException { 
     // I am selecting just one checkbox at the moment for testing purpose.. 
     if(radioTF.isSelected()){ 
      FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/tester.fxml"));  
      loader.load(); 
     } 
    } 

} 

Das Problem ist, dass kein Fehler erscheint überhaupt. Kein Kompilierungsfehler, keine Laufzeit, nichts! Es funktioniert einfach nicht!

Bitte helfen Sie mir, wo genau ich falsch liege?

Antwort

1

loader.load() gibt einen Knoten, Sie nicht zuordnen

unter diesem Link für den Hinweis Loading new fxml in the same scene

+0

Dank Werfen Sie einen Blick. Die schnelle Lösung, die auf dem Link zur Verfügung gestellt wurde, löste mein Problem nicht genau, aber eine kleine Anpassung mit dem Ankerfenster tat das: content.getChildren(). Clear(); content.getChildren(). add (FXMLLoader.load (getClass(). getResource ("/ Paket/Dateiname.fxml"))); Diese beiden Zeilen hinzugefügt, und es wurde getan! – Vishal

Verwandte Themen