Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MAIN PRESENTER CLASS//
- public class MainPresenter implements Observer{
- FxmlController mainView;
- private SettingsPresenter settingsPresenter;
- public MainPresenter(){
- try
- {
- FXMLLoader loader = new FXMLLoader();
- loader.load(getClass().getResourceAsStream("main.fxml"));
- mainView = loader.getController();
- }
- catch (IOException e)
- {
- throw new RuntimeException("Unable to load Main.fxml", e);
- }
- mainView.addObserver(this);
- }
- public Parent getView(){
- return mainView.getView();
- }
- public void showSettings(){
- System.out.println("PROVA");
- }
- @Override
- public void update(Observable o, Object arg) {
- String action = arg.toString();
- switch (action){
- case "show_settings_button":
- showSettings();
- break;
- }
- }
- }
- //FXML CONTROLLER//
- public class FxmlController extends Observable{
- @FXML private Parent root;
- public Parent getView(){
- return root;
- }
- @FXML private void handleShowSettingsButton(){
- setChanged();
- notifyObservers("show_settings_button");
- }
- }
- //main.fxml//
- <?xml version="1.0" encoding="UTF-8"?>
- <?import java.lang.*?>
- <?import javafx.geometry.*?>
- <?import javafx.geometry.Insets?>
- <?import javafx.scene.control.*?>
- <?import javafx.scene.layout.*?>
- <BorderPane fx:id="root" minWidth="-1.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="cotl.MenuWnd.Main.FxmlController">
- <center>
- <Button mnemonicParsing="false" onMouseClicked="#handleShowSettingsButton" text="Button">
- <BorderPane.margin>
- <Insets bottom="100.0" left="100.0" right="100.0" top="100.0" />
- </BorderPane.margin>
- </Button>
- </center>
- </BorderPane>
- //APP CLASS//
- public class App extends Application {
- @Override
- public void start(Stage stage) throws Exception{
- MainPresenter presenter = new MainPresenter();
- Scene scene = new Scene(presenter.getView(), 800, 600);
- stage.setScene(scene);
- stage.setTitle("PROVA");
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement