作者: twaiho2003 時間: 2016-3-23 12:37 標題: javafx 點樣由其他thread更改gui component
本帖最後由 twaiho2003 於 2016-3-23 12:39 編輯
我寫緊card reader gui ,
我用緊smartcardio 呢個package, 咁佢有d blocking function, waitForCardPresent, waitForCardPresent, 問題1, 請問係咪一定將讀卡operation 放係一個獨立thread 運作先唔會阻到gui.
問題2, 我將讀卡operation放係獨立thread, 當有卡放去個card reader, 我就讀d資料, 跟住點樣將個資料放返係gui個label上面, 我嘗試寫個public setlabel(), 但出左個Not on FX application thread; error
作者: KinChungE 時間: 2016-3-23 14:13
http://stackoverflow.com/questio ... -application-thread
Use the Platform#runLater as shown in that tutorial
作者: twaiho2003 時間: 2016-3-24 10:44
本帖最後由 twaiho2003 於 2016-3-24 10:47 編輯
回覆 2# KinChungE
請問咁樣係咪變左polling, 每秒行一次個card reader check下有冇卡, 有卡就讀, 讀完就setlabel,
方案2
定係我card reader獨立thread運行唔改, 如果一讀到資料就放落一個singleton class入面的variable,
個gui thread 就淨係check 果d variable 有冇轉變,
作者: KinChungE 時間: 2016-3-24 10:46
係叫你只將setLabel果句code放入runLater入面做
唔影響你其他code係咪background thread / polling
作者: twaiho2003 時間: 2016-3-24 10:49
回覆 4# KinChungE
原來我諗緊果陣你已經回左.
作者: twaiho2003 時間: 2016-3-29 11:36
回覆 4# KinChungE
有個低級問題想問下, 我寫左個CLASS 叫CardReader, 咁呢個CLASS直接implement runnable 定係要寫多個CardReaderThread
作者: KinChungE 時間: 2016-3-29 12:02
回覆 KinChungE
有個低級問題想問下, 我寫左個CLASS 叫CardReader, 咁呢個CLASS直接implement runnabl ...
twaiho2003 發表於 2016-3-29 11:36
隨你喜歡

