我创建了一个按钮,用于启动正在侦听服务器语音的操作,那么如何使用“停止收听”按钮使按钮停止收听服务器?
private void CallActionPerformed(java.awt.event.ActionEvent evt) {
voiceReceiver tx1 = new voiceReceiver();
tx1.captureAudio();
System.out.println("voiceReceiver is calling >>>>");
serVoice.setEnabled(false);
Call.setEnabled(false);
jButton3.setEnabled(true);
}
答案 0 :(得分:2)
将语音接收器存储在一个字段中,并在单击“停止收听”按钮时将其停止:
private void callActionPerformed(ActionEvent evt) {
this.voiceReceiver = new VoiceReceiver();
this.voiceReceiver.captureAudio();
System.out.println("voiceReceiver is calling >>>>");
serVoice.setEnabled(false);
call.setEnabled(false);
jButton3.setEnabled(true);
}
private void stopListeningActionPerformed(ActionEvent e) {
this.voiceReceiver.stopCapturingAudio();
...
}
请注意,我修复了你的namings。在Java中,按照惯例,方法以小写字母开头,类以大写字母开头。