java - Displaying JFrame -


i'm having issues figuring out how open 1 window when closes if other window initiated within sub class. here clumsy code trying use, halts setting visible of sub classe's window. perhaps due being within action event or perhaps halting main thread.

 tutorial = new tutorialwindow(); this.setvisible(false); tutorial.setlocationrelativeto(null); tutorial.setvisible(true); tutorial.setcurrentuser(users.getcurrentuser()); while(tutorial.isopen() == true ) { } this.setvisible(true); users.updateuser(tutorial.getcurrentuser()); 

my thoughts stuck in section of code until other window closes , appear again when tutorialwindow has open boolean set false due breaking while loop.

im sure matter of using correct threads, or perhaps various notify methods of not sure how that.

you using windowlistener. in following sample windowadapter implements windowlistener , override public void windowclosed(final windowevent e) method, opening second window.

import java.awt.event.windowadapter; import java.awt.event.windowevent; import javax.swing.jframe; import javax.swing.jlabel; public class testjframe { public static void main(final string args[]) { jframe jframe1 = new jframe(); jframe1.setdefaultcloseoperation(jframe.dispose_on_close); jframe1.add(new jlabel("first jframe")); jframe1.pack(); final jframe jframe2 = new jframe(); jframe2.setdefaultcloseoperation(jframe.dispose_on_close); jframe2.add(new jlabel("second jframe")); jframe2.pack(); jframe1.addwindowlistener(new windowadapter() { @override public void windowclosed(final windowevent e) { jframe2.setvisible(true); } }); jframe1.setvisible(true); } } 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -