0

could you pelase help me figure out:

  • how to convert below javaFX code as method?
  • after below is maked as method then how to call it out from other Class or from other method.?
  • what parameters I have to specify when calling out below from other class or other method?

Many thanks in advance!

Code is here:

package shuffleMyWeb;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class AliceImedemaal extends Application{

    @Override
    public void start(Stage Beginning) throws Exception {

        StackPane stack = new StackPane();
        Scene scene = new Scene(stack, 400, 400);
        Beginning.setScene(scene);
        Beginning.setTitle("Start here");

        VBox rows = new VBox();
        rows.setAlignment(Pos.CENTER);
        rows.setSpacing(50);
        stack.getChildren().add(rows);

        AnchorPane headerButtons = new AnchorPane();
        Button ExitButton = new Button("Exit");
        headerButtons.getChildren().add(ExitButton);
        headerButtons.setRightAnchor(ExitButton, 10.0);
        rows.getChildren().add(headerButtons);

        Label reveal = new Label();
        reveal.setWrapText(true);
        reveal.setText("Generates pages");
        rows.getChildren().add(reveal);

        Button Go = new Button("Go");
        rows.getChildren().add(Go);

        AnchorPane footerButtons = new AnchorPane();
        Button Seaded = new Button("Settings");
        footerButtons.getChildren().add(Seaded);
        footerButtons.setLeftAnchor(Seaded, 10.0);
        rows.getChildren().add(footerButtons);

        Beginning.show();
    }
}
  • I'm not really sure what you're asking: "How to convert JavaFX code below as method?" doesn't really make any sense. The code is already in a method called `start(...)`. What do you really mean? Perhaps http://stackoverflow.com/questions/32464698/ is similar to what you are asking. – James_D Dec 25 '15 at 12:21

1 Answers1

0

1) just declare another method below but within the class and type there your whole code and then in start() method type methodName();

example:

@Override
public void start(Stage primaryStage) throws Exception{
    method();
}

private void method(){
    StackPane stack = new StackPane();
    Scene scene = new Scene(stack, 400, 400);
    Beginning.setScene(scene);
    Beginning.setTitle("Start here");

    VBox rows = new VBox();
    rows.setAlignment(Pos.CENTER);
    rows.setSpacing(50);
    stack.getChildren().add(rows);
    // and so one
}

2) simply write methodName();

3) create new object of that class and then call method from him like this

OtherClass classVariable = new OtherClass();
classVariable.methodName();

NOTE

there might be some issues when methods are static so basically you need to have both methods static in order to use them both. The same thing with other classes but here you don't have to create an object of the class. If method is static in the other class then simply write OtherClass.methodName();

Feel free to ask anything else if something confused you

Kyle Luke
  • 348
  • 5
  • 16
  • Thanks for the answer Kyle Luke. For your answer (3) I created method called 'Algus1' code like this and it seems to be working. Does it look optimal or something is excess? Happy end of the year :)! { public class AliceImedemaal2 extends Application { public static void main(String[] args) { launch(args); } @Override public void start (Stage Stage1)throws Exception { AliceImedemaal a = new AliceImedemaal(); a.Aken1(); } }} – Andres Kostiv Dec 28 '15 at 11:26
  • well curly brackets are unnecessary. Those that are before `public class` But everything else is cool. Yeah, thanks man, you too :) – Kyle Luke Dec 29 '15 at 18:56
  • If the answer helped you, please, mark it as accepted, because stackoverflow robot system bans me from answering other question. Idk why, but whatever. Well, thank you beforehand. – Kyle Luke Dec 30 '15 at 08:42