In the following code, why is the “My Application” window the window at the front? The main method constructs this window first, right? So shouldn’t it be at the back when the “My Window” JFrame is produced?
public class MyApp extends JFrame {
public MyApp() {
super();
setSize(300,600);
setTitle("My Application");
setVisible(true);
}
public static void main(String[] args) {
MyApp application = new MyApp();
JFrame window = new JFrame();
window.setSize(600,300);
window.setTitle("My Window");
window.setVisible(true);
}
}
This is simply undefined behavior; there’s no guarantee that either window will always be in front. When I ran your code (Mac OS X, Java 6), “My Window” came up in front, but I have no doubt you’re correctly describing what happens on your system.