java - Javafx: Create new stage in application -
i need some quite simple code (i think) work. have jframe starts application play video (twice, differenct video each time) , shows couple of jbuttons answer questions on videos. problem first video show, can't create new stage. maybe can me. code in panel:
public void ausführen(int i, int antwort){ switch (antwort) { case 0: //question or video switch (i) { case 0: //film1 mp = new mediapanel(); //this application mp.run(); setvisible(false); //this timer waits video finish task = new java.util.timertask(){ @override public void run(){ setvisible(true); ausführen(1,0); } }; t = new java.util.timer(); t.schedule(task, 7000); break; case 1: //film2 mp.restart(new stage(),"other video"); setvisible(false); task = new java.util.timertask(){ @override public void run(){ setvisible(true); ausführen(2,0); dispose(); } }; t = new java.util.timer(); t.schedule(task, 7000); //next case opens jpanel jbuttons questions (works)
this code in mediapanel (the application):
public class mediapanel extends application implements runnable { private string film = "video1"; public void setfilm(string f){ film = f; } @override public void run(){ launch(); } public void start( stage stage ) throws exception { group root = new group(); stage.settitle("movieplayer"); media media = new media("video1"); mediaplayer player = new mediaplayer(media); mediaview view = new mediaview(player); view.setpreserveratio(true); root.getchildren().add(view); scene scene = new scene(root, media.getwidth(), media.getheight(), color.black); stage.setscene(scene); stage.show(); stage.setfullscreen(false); player.play(); java.util.timertask task = new java.util.timertask(){ @override public void run(){ system.out.print("still running"); //i wanted see if method called platform.exit(); } }; java.util.timer t = new java.util.timer(); t.schedule(task, 5000); } public void restart( stage stage, string film ) //i created method avoid calling launch() twice { system.out.print("restart"); group root = new group(); stage.settitle("movieplayer"); media media = new media(film); mediaplayer player = new mediaplayer(media); mediaview view = new mediaview(player); view.setpreserveratio(true); root.getchildren().add(view); scene scene = new scene(root, media.getwidth(), media.getheight(), color.black); stage.setscene(scene); stage.show(); stage.setfullscreen(true); player.play(); java.util.timertask task = new java.util.timertask(){ @override public void run(){ platform.exit(); } }; java.util.timer t = new java.util.timer(); t.schedule(task, 5000); } }
i error: "exception in thread "timer-2" java.lang.illegalstateexception: not on fx application thread; currentthread = timer-2". alternativley created new mediapanel in mediawindow, did'nt work either because 1 may not call launch() more once.
i know code isn't good, supposed easy gui/application.
i hope 1 of guys can me! thank in advance!
Comments
Post a Comment