java - JavaFX use setId() method for style sheet in different class without creating extra scene -
as can see in code makedigit() , makesmalldigit() methods way long , want them in separate file, new class. how use setid() method in different class? led function demonstrated here way many leds (i know there separate class provided not using it)
my main class:
public class digital_analog_clock_beta_1 extends application { @override public void start(stage primarystage) { double outerboxwidth = 500, outerboxheight = outerboxwidth / 3; rectangle outerbox = new rectangle(0, 0, outerboxwidth, outerboxheight); outerbox.setid("outer-box"); rectangle part1 = new rectangle(0, 0, outerboxwidth * .35, outerboxheight); part1.setid("partition"); rectangle part2 = new rectangle(outerboxwidth * .35, 0, outerboxwidth * .05, outerboxheight); part2.setid("partition-alternate"); rectangle part3 = new rectangle(outerboxwidth * .4, 0, outerboxwidth * .35, outerboxheight); part3.setid("partition"); rectangle part4 = new rectangle(outerboxwidth * .75, 0, outerboxwidth * .25, outerboxheight); part4.setid("partition"); double bignumwidth = outerboxwidth * .35; double colonwidth = outerboxwidth * .05; double digitwidth = (.9 * bignumwidth / 2) * 0.95; double digitheight = .9 * outerboxheight; double smallboxwidth = outerboxwidth * .25; double smalldigitwidth = (.9 * smallboxwidth / 2) * 0.95; double smalldigitheight = (outerboxheight / 2) * .9; digit digit1 = new digit(outerboxwidth * .02, outerboxheight * .05, digitwidth, digitheight); digit digit2 = new digit(outerboxwidth * .04 + digitwidth, outerboxheight * .05, digitwidth, digitheight); digit digit3 = new digit(outerboxwidth * .02 + bignumwidth + colonwidth, outerboxheight * .05, digitwidth, digitheight); digit digit4 = new digit(outerboxwidth * .04 + bignumwidth + colonwidth + digitwidth, outerboxheight * .05, digitwidth, digitheight); smalldigit uppersmalldigit1 = new smalldigit(bignumwidth * 2 + colonwidth + smallboxwidth * .04, outerboxheight * .03, smalldigitwidth, smalldigitheight); smalldigit uppersmalldigit2 = new smalldigit(bignumwidth * 2 + colonwidth + smallboxwidth * .08 + smalldigitwidth, outerboxheight * .03, smalldigitwidth, smalldigitheight); smalldigit lowersmalldigit1 = new smalldigit(bignumwidth * 2 + colonwidth + smallboxwidth * .04, outerboxheight * .07 + smalldigitheight, smalldigitwidth, smalldigitheight); smalldigit lowersmalldigit2 = new smalldigit(bignumwidth * 2 + colonwidth + smallboxwidth * .08 + smalldigitwidth, outerboxheight * .07 + smalldigitheight, smalldigitwidth, smalldigitheight); pane pane = new pane(); pane.getchildren().add(outerbox); pane.getchildren().addall(part1, part2, part3, part4); off(digit1); off(digit2); off(digit3); off(digit4); offsmall(lowersmalldigit2); offsmall(lowersmalldigit1); offsmall(uppersmalldigit2); offsmall(uppersmalldigit1); pane.getchildren().addall(digit1, digit2, digit3, digit4, uppersmalldigit1, uppersmalldigit2, lowersmalldigit1, lowersmalldigit2); scene scene = new scene(pane, outerboxwidth, outerboxheight); scene.getstylesheets().add(getclass().getresource("stylesheet.css").toexternalform()); primarystage.settitle("digital analog clock beta 1"); primarystage.setscene(scene); primarystage.show(); animationtimer animator = new animationtimer() { @override public void handle(long arg0) { // update date date = new date(); calendar calendar = calendar.getinstance(); calendar.settime(date); int minutes = calendar.get(calendar.minute); int hours = calendar.get(calendar.hour_of_day); int seconds = calendar.get(calendar.second); int unitsminutes = minutes % 10; int tensminutes = minutes / 10; int unitsseconds = seconds % 10; int tensseconds = seconds / 10; int unitshours = hours % 10; int tenshours = hours / 10; // render off(digit1); off(digit2); off(digit3); off(digit4); offsmall(lowersmalldigit2); offsmall(lowersmalldigit1); offsmall(uppersmalldigit2); offsmall(uppersmalldigit1); makedigit(digit1, tenshours); makedigit(digit2, unitshours); makedigit(digit3, tensminutes); makedigit(digit4, unitsminutes); makesmalldigit(uppersmalldigit1, tensseconds); makesmalldigit(uppersmalldigit2, unitsseconds); // makesmalldigit(); } }; animator.start(); } public void off(digit digit) { digit.bottom.setid("off-digits"); digit.middle.setid("off-digits"); digit.top.setid("off-digits"); digit.lowerleft.setid("off-digits"); digit.upperleft.setid("off-digits"); digit.lowerright.setid("off-digits"); digit.upperright.setid("off-digits"); } public void offsmall(smalldigit digit) { digit.bottom.setid("off-digits"); digit.middle.setid("off-digits"); digit.top.setid("off-digits"); digit.lowerleft.setid("off-digits"); digit.upperleft.setid("off-digits"); digit.lowerright.setid("off-digits"); digit.upperright.setid("off-digits"); } public void makedigit(digit digit, int n) { if (n == 0) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.lowerleft.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } else if (n == 1) { digit.upperright.setid("digits"); digit.lowerright.setid("digits"); } else if (n == 2) { digit.top.setid("digits"); digit.upperright.setid("digits"); digit.middle.setid("digits"); digit.lowerleft.setid("digits"); digit.bottom.setid("digits"); } else if (n == 3) { digit.lowerright.setid("digits"); digit.upperright.setid("digits"); digit.top.setid("digits"); digit.middle.setid("digits"); digit.bottom.setid("digits"); } else if (n == 4) { digit.middle.setid("digits"); digit.lowerright.setid("digits"); digit.upperleft.setid("digits"); digit.upperright.setid("digits"); } else if (n == 5) { digit.top.setid("digits"); digit.middle.setid("digits"); digit.bottom.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); } else if (n == 6) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.middle.setid("digits"); digit.lowerleft.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); //digit.upperright.setid("digits"); } else if (n == 7) { digit.top.setid("digits"); //digit.bottom.setid("digits"); //digit.middle.setid("digits"); //digit.lowerleft.setid("digits"); //digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } else if (n == 8) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.middle.setid("digits"); digit.lowerleft.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } else if (n == 9) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.middle.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } } public void makesmalldigit(smalldigit digit, int n) { if (n == 0) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.lowerleft.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } else if (n == 1) { digit.upperright.setid("digits"); digit.lowerright.setid("digits"); } else if (n == 2) { digit.top.setid("digits"); digit.upperright.setid("digits"); digit.middle.setid("digits"); digit.lowerleft.setid("digits"); digit.bottom.setid("digits"); } else if (n == 3) { digit.lowerright.setid("digits"); digit.upperright.setid("digits"); digit.top.setid("digits"); digit.middle.setid("digits"); digit.bottom.setid("digits"); } else if (n == 4) { digit.middle.setid("digits"); digit.lowerright.setid("digits"); digit.upperleft.setid("digits"); digit.upperright.setid("digits"); } else if (n == 5) { digit.top.setid("digits"); digit.middle.setid("digits"); digit.bottom.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); } else if (n == 6) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.middle.setid("digits"); digit.lowerleft.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); } else if (n == 7) { digit.top.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } else if (n == 8) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.middle.setid("digits"); digit.lowerleft.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } else if (n == 9) { digit.top.setid("digits"); digit.bottom.setid("digits"); digit.middle.setid("digits"); digit.upperleft.setid("digits"); digit.lowerright.setid("digits"); digit.upperright.setid("digits"); } } public static void main(string[] args) { launch(args); } }
Comments
Post a Comment