I try to developp an application and I work on Eclipse.
First I worked on four files :
Main.java, that launch the interface by using the sheet1.fxml file
MyController.java, that declares the button and the anchor of the fxml file sheet1. That file implements an action event : to go on a second interface (sheet2.fxml) after clicking on the button of the first fxml file (that is sheet1).
Now I want to work on the second interface, sheet2.fxml. I'd like to :
- add text based on a count of files in a folder
- create buttons in order to go on a third interface
But my question is how could I do ?
I tried to create a second controller to make the declaration of the Text nbExcel and buttons then build the relation with sheet2.fxml file but I don't see the trick.
How to associate events that run the components located on that sheet2 and that new controller ?
I began to do that on "myController2" :
public class myController2 extends Application {
// How and where to associate that controller with the fxml file "sheet2" ?
public void start2() throws IOException{
Stage primaryStage2 = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("sheet1.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage2.setScene(scene);
primaryStage2.show();
}
@FXML
// declaration text in order to count files in folder in sheet2 interface
private Text nbExcel;
// declaration action buttons in sheet2 interface
// To do
// 1 - INITIALISATION
public void initialize(URL location, ResourceBundle resources) {
File a = new File("C:/Controles/Excel");
int b = 0;
for (File file : a.listFiles()) {
if (file.isFile() && (file.getName().endsWith(".xlsx") )) {
b++;
}
}
nbExcel.setText(Integer.toString(b));
}
Any help would be really appreciated.
Thank you !