f*******g 发帖数: 55 | 1 I'm working on a multithread Java program: one thread for some computations
and the other thread for GUI. I'm trying to show the results of the
computation thread on the GUI in real time, but I'm not sure how to notify
the GUI thread when the results are updated. I checked some tutorials on
event handling, but all of them are about handling the actions by users. Is
there a way to handle the actions by another thread? Thanks a lot! |
D**C 发帖数: 6754 | 2 observer design pattern
computations
Is
【在 f*******g 的大作中提到】 : I'm working on a multithread Java program: one thread for some computations : and the other thread for GUI. I'm trying to show the results of the : computation thread on the GUI in real time, but I'm not sure how to notify : the GUI thread when the results are updated. I checked some tutorials on : event handling, but all of them are about handling the actions by users. Is : there a way to handle the actions by another thread? Thanks a lot!
|
o**2 发帖数: 168 | |
o**2 发帖数: 168 | |
z*******3 发帖数: 13709 | 5 你说的是哪一个ui?
awt, swing还是javafx?
javafx需要你更改现有代码,用上InegerProperty, StringPorperty这些
然后再将ui的property绑定到这些property上去
http://docs.oracle.com/javafx/2/binding/jfxpub-binding.htm
如果是swing的话,参考这篇文章
http://docs.oracle.com/javase/tutorial/uiswing/components/progr
如果是awt的话,你需要自己手动处理闪烁等问题
每次刷新屏幕的时候,就去结果里面轮询一下就是了 |
b***i 发帖数: 3043 | 6 以Swing为例,有一个JTextPane jTP;你自己在开始的时候在UI线程初始化。
一般在计算线程里面SwingUtilities.invokeLater(new Runnable(){
public void run(){
jTP.setText("new stuff here");
jTP.setVisible, setEnabled, color, font, whatever change can be done here.
}});
如果是绘图,有其他的方案。
computations
Is
【在 f*******g 的大作中提到】 : I'm working on a multithread Java program: one thread for some computations : and the other thread for GUI. I'm trying to show the results of the : computation thread on the GUI in real time, but I'm not sure how to notify : the GUI thread when the results are updated. I checked some tutorials on : event handling, but all of them are about handling the actions by users. Is : there a way to handle the actions by another thread? Thanks a lot!
|
c*********e 发帖数: 16335 | 7 难道我是穿越了,这年月还有人用swing?
【在 b***i 的大作中提到】 : 以Swing为例,有一个JTextPane jTP;你自己在开始的时候在UI线程初始化。 : 一般在计算线程里面SwingUtilities.invokeLater(new Runnable(){ : public void run(){ : jTP.setText("new stuff here"); : jTP.setVisible, setEnabled, color, font, whatever change can be done here. : }}); : 如果是绘图,有其他的方案。 : : computations : Is
|
l*********s 发帖数: 5409 | 8 那用啥?
【在 c*********e 的大作中提到】 : 难道我是穿越了,这年月还有人用swing?
|
D**C 发帖数: 6754 | 9 那用啥
【在 c*********e 的大作中提到】 : 难道我是穿越了,这年月还有人用swing?
|
z*******3 发帖数: 13709 | 10 javafx
【在 D**C 的大作中提到】 : 那用啥
|
b***i 发帖数: 3043 | 11 Java SE确定带fx了吗?
【在 z*******3 的大作中提到】 : javafx
|