进一步阐述我的问题,我正在JavaFX中开发一个问题库。在主屏幕上,我希望在按钮点击的基础上提供基于单选按钮的导航。
e.g。如果我选择了radiobutton选项,然后单击按钮继续前进,它应该指向我创建的FXML屏幕文件。为了进一步解释我想要保留的内容,下面是GUI快照。
我正在粘贴下面的代码:
Main HomeScreen FXML文件:
<?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控制器文件:
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();
}
}
}
问题在于根本没有出现错误。没有编译时错误,没有运行时,没有!它只是不起作用!
请问我哪里出错?