java - JavaFx Stageshow 3 different stage -
i have on 3 class , 3 stage , want this: want show stage . 1 time show 1st stage 10 sec, next show 2nd stage 10 sec , next show 3rd stage 10 sec , next show 1st .... important 3 stage have work time .
in swing use cardlayout here don't know how this.
code 1 class:
public class simpleslideshowtest extends application{ class simpleslideshow { stackpane root = new stackpane(); imageview[] slides; public simpleslideshow() { this.slides = new imageview[4]; file file1 = new file("c:/users/022/workspace22/ekranlcd/res/images/belka.png"); image image1 = new image(file1.touri().tostring()); file file = new file("c:/users/022/workspace22/ekranlcd/res/images/kropka.png"); image image2 = new image(file.touri().tostring()); image image3 = new image(file1.touri().tostring()); image image4 = new image(file1.touri().tostring()); slides[0] = new imageview(image1); slides[1] = new imageview(image2); slides[2] = new imageview(image3); slides[3] = new imageview(image4); } public stackpane getroot() { return root; } // method running in class public void start() { sequentialtransition slideshow = new sequentialtransition(); (imageview slide : slides) { sequentialtransition sequentialtransition = new sequentialtransition(); fadetransition fadein = getfadetransition(slide, 0.0, 1.0, 0); pausetransition stayon = new pausetransition(duration.millis(2000)); fadetransition fadeout = getfadetransition(slide, 0, 0.0, 2000); sequentialtransition.getchildren().addall(fadein, stayon, fadeout); slide.setopacity(0); this.root.getchildren().add(slide); slideshow.getchildren().add(sequentialtransition); } slideshow.play(); } // method in transition helper class: public fadetransition getfadetransition(imageview imageview, double fromvalue, double tovalue, int durationinmilliseconds) { fadetransition ft = new fadetransition(duration.millis(durationinmilliseconds), imageview); ft.setfromvalue(fromvalue); ft.settovalue(tovalue); return ft; } } public static void main(string[] args) { launch(args); } @override public void start(stage primarystage) throws exception { simpleslideshow simpleslideshow = new simpleslideshow(); text msg = new text("java2s.com d sad adas dsa sad dsa dsa dsa dsa sdasa dsa dsa"); msg.setfont(font.font ("verdana", 40)); msg.sety(config.ysize-(config.ysize/6)); pane root1 = new pane(msg); root1.setlayoutx(config.xsize/2); root1.setlayouty(config.ysize-(config.ysize/5)); root1.setprefsize(config.xsize/2,400); main2.start(msg); simpleslideshow.getroot().getchildren().add(root1); scene scene = new scene(simpleslideshow.getroot()); primarystage.setscene(scene); primarystage.show(); simpleslideshow.start(); } }
my second class want add
public class testurlimage4 extends application { public static arraylist<busstop2> list = new arraylist<>(); public static arraylist<positiontilesandurlpaths> positiontilesandurlpathslist = new arraylist<>(); public static hashmap<string, image> imgcache = new hashmap<>(); public static double lat; public static double lon; public static double deltay; public static double deltax; public static double positionx; public static double positiony; public static int[] imagecount = getcountimage(); public static int [] countimage = countimage(); public static int []x = new int [countimage[0]]; public static int []y = new int [countimage[1]]; private file file = new file("c:/users/eltegps 022/workspace22/ekranlcd/res/images/kropka.png"); private image bus = new image(file.touri().tostring()); public testurlimage4() { } testurlimage4(double lat, double lon){ int [] tiles= gettilenumber(lat, lon, config.mapzoom); deltax = tile2lon(tiles[0] + 1 , config.mapzoom) - tile2lon(tiles[0], config.mapzoom); deltay = tile2lat(tiles[1], config.mapzoom) - tile2lat(tiles[1] + 1 , config.mapzoom); positionx = (lon - tile2lon(tiles[0], config.mapzoom)) * config.imgsize/deltax; positiony = (tile2lat(tiles[1], config.mapzoom) - lat) * config.imgsize/deltay; gettiles(lat,lon); getimgpositionandurlspath(list); } /** * method use count of image need * @return */ private static int[] getcountimage(){ int ximagecount = (int) math.ceil(config.xsize/256); int yimagecount = (int) math.ceil(config.ysize/256); return new int[] {ximagecount, yimagecount}; } /** * method use count of tiles * @return */ public static int[] countimage(){ int ximagecount = imagecount[0]; int yimagecount = imagecount[1]; if(ximagecount-1 %2 != 0){ ximagecount = ximagecount + 2; } if(yimagecount-1 %2 != 0){ yimagecount = yimagecount + 2; } return new int[] {ximagecount, yimagecount}; } /** * method use tiles * @param lat * @param lon * @return */ private static arraylist<busstop2> gettiles(double lat, double lon ){ int [] numbertile = gettilenumber(lat, lon, config.mapzoom); int a1 = 1; int a2 = 1; int a3 = 1; int a4 = 1; x[0] = numbertile[0]; y[0] = numbertile[1]; (int = 1; i<x.length; i++){ if(i%2==0){ x[i] = numbertile[0]+(a1); a1++; } else{ x[i] = numbertile[0]-(a2); a2++; } } (int = 1; i<y.length; i++){ if(i%2==0){ y[i] = numbertile[1]+(a3); a3++; } else{ y[i] = numbertile[1]-(a4); a4++; } } for(int = 0 ; i<x.length ; i++){ (int j = 0 ;j<y.length ; j++ ){ list.add(new busstop2(x[i], y[j], x[0] - x[i], y[0]-y[j])); } } return list; } /** * * @param list * @return */ private static arraylist<positiontilesandurlpaths> getimgpositionandurlspath(arraylist<busstop2> list){ for(busstop2 bus : list){ positiontilesandurlpathslist.add(new positiontilesandurlpaths(256*bus.getx(), 256*bus.gety(), config.mappath + "/" + bus.geta() + "/" + bus.getb() + ".png")); } return positiontilesandurlpathslist; } public static int [] gettilenumber(final double lat, final double lon, final int zoom) { int xtile = (int)math.floor( (lon + 180) / 360 * (1<<zoom) ) ; int ytile = (int)math.floor( (1 - math.log(math.tan(math.toradians(lat)) + 1 / math.cos(math.toradians(lat))) / math.pi) / 2 * (1<<zoom) ) ; if (xtile < 0) xtile=0; if (xtile >= (1<<zoom)) xtile=((1<<zoom)-1); if (ytile < 0) ytile=0; if (ytile >= (1<<zoom)) ytile=((1<<zoom)-1); return new int[] {xtile, ytile}; } static double tile2lon(int x, int z) { return x / math.pow(2.0, z) * 360.0 - 180; } static double tile2lat(int y, int z) { double n = math.pi - (2.0 * math.pi * y) / math.pow(2.0, z); return math.todegrees(math.atan(math.sinh(n))); } @override public void start(stage stage) throws exception { canvas canvas = new canvas(config.xsize, config.ysize); graphicscontext gc = canvas.getgraphicscontext2d(); int [] aa =gettilenumber(51.401968,16.205556, 18); gettiles(51.401968,16.205556); getimgpositionandurlspath(list); executorservice executor = executors.newfixedthreadpool(10); arraylist<utltoimageconverter> threadlist = new arraylist<>(); for(positiontilesandurlpaths url : positiontilesandurlpathslist){ threadlist.add(new utltoimageconverter(url.getpath())); } try { executor.invokeall(threadlist); } catch (interruptedexception e1) { e1.printstacktrace(); } system.out.println(imgcache.size()); system.out.println( aa[0] + " " + aa[1] ); for(positiontilesandurlpaths pos : getimgpositionandurlspath(list)){ gc.drawimage(imgcache.get(pos.getpath()),config.xsize/2-pos.getx()-config.imgsize/2 ,(config.ysize/2)- pos.gety()-config.imgsize/2, config.imgsize, config.imgsize); } gc.drawimage(bus,config.xsize/2-config.imgsize/2-config.markwidth/2+(int)positionx, config.ysize/2+(int)positiony-config.imgsize/2-config.markheight/2, config.markwidth, config.markheight); pane root = new pane(); root.getchildren().add(canvas); scene scene = new scene(root); stage.setscene(scene); stage.show(); } public static void main(string[] args) { application.launch(args); } }
Comments
Post a Comment