java - JavaFX static/non static with Controllers -
i've tried make little math programm javafx, have button action in controller 1:
@fxml public void showcalc(actionevent event2) { layout.parabel_nullstelle_showcalc.setvariables(a, b, c, x1, x2, ze1, ze2, ze3, ze4, ze5, ze6, ze7); parent root3 = main.main.getparent(); scene showcalc = new scene(root3, 500, 1000); stage paranullcalc = new stage(); paranullcalc.settitle("rechung"); paranullcalc.setscene(showcalc); paranullcalc.show(); }
it opens new stage scene contains calculation. in controller showcalc have set variables method.
public static void setvariables(double a1, double b1, double c1,double x11, double x22, double ze11, double ze22, double ze33, double ze44, double ze55, double ze66, double ze77){ = (float) a1; b = (float) b1; c = (float) c1; x1 = (float) x11; x2 = (float) x22; ze1 = (float) ze11; ze2 = (float) ze22; ze3 = (float) ze33; ze4 = (float) ze44; ze5 = (float) ze55; ze6 = (float) ze66; ze7 = (float) ze77; }
i needed make static cause can't object of controller, , import static/non static error, want change text of textarea in same scene setvariables, can show calculation, can't make textarea static, crashes, can't access without static, , creating object of isn't solution, how solve this?
don't make variables or methods in controller static
solely purpose of being able access them elsewhere. rarely, if ever, makes sense have static
members in controller.
to access method in controller, retrieve controller instance fxmlloader
. haven't posted enough code provide complete answer, need like:
fxmlloader loader = new fxmlloader(getclass().getresource("calc.fxml")); parent calcroot = loader.load(); calccontroller controller = loader.getcontroller(); controller.setvariables(...); scene showcalc = new scene(calcroot, 500, 1000); // ...
and remove static
setvariables
method declaration in controller class.
Comments
Post a Comment