the code will show you what im trying to do, I hope you understand

im new to programming but know the basics of java and im trying to add Object Oriented Programming to my apps so its not procedural
thanks , if you need more info to understand just ask me.

   package myApp;

    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class Main extends Application {

        @Override
        public void start(Stage myStage) throws Exception

        {

            VBox root = new VBox();

            Scene scene = new Scene(root);

            myStage.setScene(scene);

            myStage.show();

            Button btn = new Button("Click Me");

            root.getChildren().add(btn);

            bank yo = new bank();

            btn.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {

                    bank.customer();

                }
            });

        }

        public static void main(String[] args) {
            Application.launch(args);

        }
    }

package myApp;

import javafx.scene.control.Button;

public class bank

{

    public static void customer()

    {

        btn.setText("yo");

    }

}

Recommended Answers

All 2 Replies

just to clarify the code is not working

In OO each object has a public interface and a private implementation. No object has access to any other object's private implementation. This massively simplifies the overall architecture by restricting the number of ways that objects can interact. What you are doing here violates that; the bank object is trying to fiddle with part of the GUI's implementation.

The standard architectural solution to this is called MVC. There's loads of stuff on the web about it, but here's a good starting explanation. Google for more.

When you've read that, note that in JavaFX the model and the controller are very often combined in one class, but the model is always separate and independent.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.