-4

我制作了一个按钮来启动正在收听服务器语音的操作,那么如何使用“停止收听”按钮制作一个按钮来停止收听服务器?

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);
 }   
4

1 回答 1

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();
    ...
}

请注意,我修正了您的命名。在 Java 中,按照惯例,方法以小写字母开头,类以大写字母开头。

于 2012-09-27T14:50:34.133 回答