Class SwingResponseListener

java.lang.Object
com.chatmotorapi.api.listener.SwingResponseListener
All Implemented Interfaces:
MotorResponseListener

public class SwingResponseListener
extends Object
implements MotorResponseListener
A Swing implementation of MotorResponseListener that updates a JTextArea with the received response chunks. Includes an option to append a new line after each chunk.
  • Constructor Details

    • SwingResponseListener

      public SwingResponseListener​(JTextArea textArea, boolean appendNewLine)
      Constructor.
      Parameters:
      textArea - the JTextArea to update with the received response chunks
      appendNewLine - if true, a new line will be appended after each chunk
  • Method Details

    • onChunkReceived

      public void onChunkReceived​(MotorResponse motorResponse)
      Description copied from interface: MotorResponseListener
      Called when a new chunk of response is received.
      Specified by:
      onChunkReceived in interface MotorResponseListener
      Parameters:
      motorResponse - the ChatMotor response.
    • onResponseCompleted

      public void onResponseCompleted()
      Description copied from interface: MotorResponseListener
      Called when the response streaming is successfully completed. This method is only invoked if the entire process completes without encountering any errors.
      Specified by:
      onResponseCompleted in interface MotorResponseListener
    • onError

      public void onError​(Throwable throwable)
      Description copied from interface: MotorResponseListener
      Called when an error occurs during the response streaming.
      Specified by:
      onError in interface MotorResponseListener
      Parameters:
      throwable - the exception that occurred during streaming.