【发布时间】:2014-05-19 04:26:55
【问题描述】:
我正在学习 JavaFX。而且我只能在 main 方法中看到一个 launch(args) 方法。当我调试到启动时。我看不到任何调用 start() 的语句。那么 JavaFX 程序什么时候调用 start 方法? 这是 launch(args) 源代码。
public static void launch(String... args) {
// Figure out the right class to call
StackTraceElement[] cause = Thread.currentThread().getStackTrace();
boolean foundThisMethod = false;
String callingClassName = null;
for (StackTraceElement se : cause) {
// Skip entries until we get to the entry for this class
String className = se.getClassName();
String methodName = se.getMethodName();
if (foundThisMethod) {
callingClassName = className;
break;
} else if (Application.class.getName().equals(className)
&& "launch".equals(methodName)) {
foundThisMethod = true;
}
}
if (callingClassName == null) {
throw new RuntimeException("Error: unable to determine Application class");
}
try {
Class theClass = Class.forName(callingClassName, true,
Thread.currentThread().getContextClassLoader());
if (Application.class.isAssignableFrom(theClass)) {
Class<? extends Application> appClass = theClass;
LauncherImpl.launchApplication(appClass, args);
} else {
throw new RuntimeException("Error: " + theClass
+ " is not a subclass of javafx.application.Application");
}
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
【问题讨论】:
-
只是对JavaFX有点熟悉,我猜
launch方法将一个事件放到将调用start的事件队列中,这样start就可以保证在内部被调用它的 gui 线程的上下文...JavaFX 怎么称呼它... -
你在 try/catch 块中查看过
LauncherImpl.launchApplication()吗? -
是的,我试过了,它停在了 launchLatch.await();
-
@deathlee 这意味着有另一个线程在某处工作......想知道那是什么线程。