app01/
`-src/
|-controllers/
| `-MainController.java
|-models/
| `-MainModel.java
`views/
`-MainView.java
- App.java
import controllers.MainController;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import models.MainModel;
import views.MainView;
public class App extends Application {
public void start(Stage primaryStage) {
MainView mainWindow = new MainView();
MainModel mainModel = new MainModel();
new MainController(mainWindow, mainModel);
Scene scene = new Scene(mainWindow, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
- views/MainView.java
package views;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
public class MainView extends VBox {
public Button button;
public MainView() {
Text text = new Text("Helló Világ");
button = new Button("Mehet");
this.getChildren().add(text);
this.getChildren().add(button);
}
}
- controllers/MainController.java
package controllers;
import models.MainModel;
import views.MainView;
public class MainController {
MainView mainWindow;
MainModel mainModel;
public MainController(MainView mainWindow, MainModel mainModel) {
this.mainWindow = mainWindow;
this.mainModel = mainModel;
eventsHandler();
}
public void eventsHandler() {
this.mainWindow.button.setOnAction( event -> {
System.out.println("Kattintás törtétn");
System.out.println(mainModel.getNum());
});
}
}
- models/MainModel.java
package models;
public class MainModel {
public int getNum() {
return 15;
}
}