0
我有一個語音識別系統,這是listen(button)
功能我的java swing應用程序jcomponents不會繪製,僅在計算完成後重繪?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jButton1.setIcon(loading_icon);
microphone.startRecording()
jButton1.setIcon(speak_icon);
System.out.println("Start speaking. Press Ctrl-C to quit.\n");
result = recognizer.recognize();
if (result != null) {
String bestfinalnofiller = result.getBestFinalResultNoFiller();
String hypothesis = result.getBestPronunciationResult();
String getresult = result.getBestResultNoFiller();
System.out.println("You said: " + bestfinalnofiller + '\n');
System.out.println("You said: " + hypothesis + '\n');
System.out.println("You said: " + getresult + '\n');
} else {
}
}
我的結果會是這樣的: 按鈕圖標保持不變,並在下班後的變化是在同時工作完成 系統打印去串"start speaking..."
recognizer.recognize()
功能:
public Result recognize(String referenceText) throws IllegalStateException {
Result result = null;
checkState(State.READY);
try {
setState(State.RECOGNIZING);
result = decoder.decode(referenceText);
} finally {
setState(State.READY);
}
return result;
}
我嘗試添加:
SwingUtilities.invokeLater
,但沒有工作,請大家幫幫我,我想使該鍵可以改變它的圖標圖像而計算...
但是爲什麼不在擺到另一條線上時修復繪製未上漆的圖形,除了'SwingWorker'之外,還有什麼解決方案嗎?再次感謝 –
@malekh因爲Swing是一個單線程框架,就像大多數GUI框架一樣。在EDT的上下文中調用'actionPerformed',這意味着在該方法存在之前,它不能處理下一系列事件(包括繪畫事件)。這就是它的工作原理。 – MadProgrammer
如果使用EDIT的上下文調用'actionPerformed',是否有使用'鼠標點擊'功能或'on-release'功能。 –