8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package hello;
27
28 import javafx.application.Application;
29 import javafx.scene.Group;
30 import javafx.scene.Scene;
31 import javafx.scene.paint.Color;
32 import javafx.scene.shape.Rectangle;
33 import javafx.stage.Stage;
34
35 public class HelloLaunchOnNewThread extends Application {
36
37 static long startTime;
38
39 public HelloLaunchOnNewThread() {
40 long endTime = System.nanoTime();
41 long elapsedMsec = (endTime - startTime + 500000) / 1000000;
42 System.err.println("DONE: elapsed time = " + elapsedMsec + " msec");
43 System.err.println("Constructor: currentThread="
44 + Thread.currentThread().getName());
45 }
46
47 @Override public void init() {
48 System.err.println("init: currentThread="
49 + Thread.currentThread().getName());
50 }
51
52 @Override public void start(Stage stage) {
53 System.err.println("start: currentThread="
54 + Thread.currentThread().getName());
55
56 stage.setTitle("Launch from New Thread");
57
58 Group root = new Group();
59 Scene scene = new Scene(root, 600, 450);
60 scene.setFill(Color.LIGHTGREEN);
61
62 Rectangle rect = new Rectangle();
63 rect.setX(25);
64 rect.setY(40);
65 rect.setWidth(100);
66 rect.setHeight(50);
67 rect.setFill(Color.RED);
68
69 root.getChildren().add(rect);
70 stage.setScene(scene);
71 stage.show();
72 System.err.println("You should now see the 'HelloWorld' rectangle in the window");
73 }
74
75 @Override public void stop() {
76 System.err.println("stop: currentThread="
77 + Thread.currentThread().getName());
78 }
79
80 /**
81 * @param args the command line arguments
82 */
83 public static void main(final String[] args) {
84 System.err.println("main: currentThread="
85 + Thread.currentThread().getName());
86 new Thread(() -> {
87 // Sleep for a very short time to ensure main thread exits,
88 // since that will provoke RT-9824
89 try {
90 Thread.sleep(100);
91 } catch (InterruptedException ex) {}
92 System.err.println("Calling Application.launch from currentThread="
93 + Thread.currentThread().getName());
94 System.err.print("LAUNCHING...");
95 System.err.flush();
96 startTime = System.nanoTime();
97 Application.launch(HelloLaunchOnNewThread.class, args);
98 System.err.println("Application.launch returns");
99 }).start();
100 System.err.println("Main thread exiting: currentThread="
101 + Thread.currentThread().getName());
102 }
103 }
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package hello;
27
28 import java.util.concurrent.atomic.AtomicBoolean;
29 import javafx.application.Application;
30 import javafx.scene.Group;
31 import javafx.scene.Scene;
32 import javafx.scene.paint.Color;
33 import javafx.scene.shape.Rectangle;
34 import javafx.stage.Stage;
35
36 public class HelloLaunchOnNewThread extends Application {
37
38 static long startTime;
39 static AtomicBoolean mainCalled = new AtomicBoolean(false);
40
41 public HelloLaunchOnNewThread() {
42 long endTime = System.nanoTime();
43 long elapsedMsec = (endTime - startTime + 500000) / 1000000;
44 System.err.println("DONE: elapsed time = " + elapsedMsec + " msec");
45 System.err.println("Constructor: currentThread="
46 + Thread.currentThread().getName());
47 if (!mainCalled.get()) {
48 System.err.println("***************************************");
49 System.err.println("*** ERROR: main() method not called ***");
50 System.err.println("***************************************");
51 }
52 }
53
54 @Override public void init() {
55 System.err.println("init: currentThread="
56 + Thread.currentThread().getName());
57 }
58
59 @Override public void start(Stage stage) {
60 System.err.println("start: currentThread="
61 + Thread.currentThread().getName());
62
63 stage.setTitle("Launch from New Thread");
64
65 Group root = new Group();
66 Scene scene = new Scene(root, 600, 450);
67 scene.setFill(Color.LIGHTGREEN);
68
69 Rectangle rect = new Rectangle();
70 rect.setX(25);
71 rect.setY(40);
72 rect.setWidth(100);
73 rect.setHeight(50);
74 rect.setFill(Color.RED);
75
76 root.getChildren().add(rect);
77 stage.setScene(scene);
78 stage.show();
79 System.err.println("You should now see the 'HelloWorld' rectangle in the window");
80 }
81
82 @Override public void stop() {
83 System.err.println("stop: currentThread="
84 + Thread.currentThread().getName());
85 }
86
87 /**
88 * @param args the command line arguments
89 */
90 public static void main(final String[] args) {
91 mainCalled.set(true);
92 System.err.println("main: currentThread="
93 + Thread.currentThread().getName());
94 new Thread(() -> {
95 // Sleep for a very short time to ensure main thread exits,
96 // since that will provoke RT-9824
97 try {
98 Thread.sleep(100);
99 } catch (InterruptedException ex) {}
100 System.err.println("Calling Application.launch from currentThread="
101 + Thread.currentThread().getName());
102 System.err.print("LAUNCHING...");
103 System.err.flush();
104 startTime = System.nanoTime();
105 Application.launch(HelloLaunchOnNewThread.class, args);
106 System.err.println("Application.launch returns");
107 }).start();
108 System.err.println("Main thread exiting: currentThread="
109 + Thread.currentThread().getName());
110 }
111 }
|