JavaFX 线程问题 - 方法调用运行时 GUI 冻结
我希望有人能够提供帮助,因为我有点困惑。我有一个 javafx 类,它运行一个用户界面,其中包括一个用于大声朗读一些文本的按钮。当您按下它时,它会调用一个 Java 对象,该对象使用 FreeTTS java 语音合成器来大声读出字符串,一切正常。
问题是,当朗读演讲时,程序完全停止,直到完成。我不是线程应用程序方面的专家,但我知道通常如果我扩展 Thread 类,并在重写的 run 方法中提供语音合成代码的实现,当我在类上调用 start 时,它“应该”创建一个new Thread,并在那里运行此代码,从而允许打开 JavaFX GUI 的主线程正常继续。
知道为什么情况并非如此吗?预先非常感谢!
I hoped someone might be able to help as I'm a little stumped. I have a javafx class which runs a user interface, which includes a button to read some text out loud. When you press it, it invokes a Java object which uses the FreeTTS java speech synth to read out loud a String, which all works fine.
The problem is, when the speech is being read out, the program stops completely until its completed. I'm not an expert on threaded applications, but I understand that usually if I extend the Thread class, and provided my implementation of the speech synth code inside an overridden run method, when I call start on the class it "should" create a new Thread, and run this code there, allowing the main thread which has the JavaFX GUI on to continue as normal.
Any idea why this isn't the case? Thanks a lot in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确认 - 我已经解决了!我调用了该类的 start() 方法而不是 run() 及其排序方法。现在看来是如此明显!
Ack - I've solved it! I called the start() method of the class rather than run() and its sorted. Seems so obviously when looking now!