java - Why isn't my program using the variables? -
i trying make object orientated javafx program have encountered problem can't seem fix, window variables set , when print them console set when come use them in start method doesn't seem acknowledge there.
main class:
import com.mersey.ui.window; public class main { public static void main(string[] args) { window win = new window(); win.create("mersey", 980, 640, false); window.launch(window.class, args); } }
window class:
package com.mersey.ui; import javafx.application.application; import javafx.scene.scene; import javafx.scene.layout.pane; import javafx.stage.stage; public class window extends application { protected stage windowstage; protected pane windowroot; protected scene windowscene; protected string windowtitle; protected int windowwidth; protected int windowheight; protected boolean windowresizable; public void create(string title, int width, int height, boolean resizable) { windowtitle = title; windowwidth = width; windowheight = height; windowresizable = resizable; /* system.out.print(windowtitle+"\n"); system.out.print(windowwidth+"\n"); system.out.print(windowheight+"\n"); system.out.print(windowresizable);*/ } @override public void start(stage stage) throws exception { windowstage = stage; windowroot = new pane(); windowscene = new scene(windowroot, windowwidth, windowheight); windowstage.setscene(windowscene); windowstage.settitle(windowtitle); windowstage.setwidth(windowwidth); windowstage.setheight(windowheight); windowstage.setminwidth(windowwidth); windowstage.setminheight(windowheight); windowstage.setresizable(windowresizable); windowstage.show(); } }
i think* youre going want here, not construct window object call window.launch in way now, instead, funnel values width height , via string[] args passed window.launch. documentation says can retreive values via getparameters(), this:
//in main string[] launchargs = new string[] {"width=800", "height=600"}; window.launch(window.class, launchargs); .......................... //in start(stage) string[] args = getparameters(); (string s : args) { if (s.contains("width")) { //parse , set window width here } }
see this: http://docs.oracle.com/javafx/2/api/javafx/application/application.html#launch(java.lang.class, java.lang.string...)
of course, assumes want able supply arbitrary values class fields within main. if not, hard code default value, or pull them config in start(stage) method.
Comments
Post a Comment