public void subscription(String topic,int qos,boolean sub){
  setTitleText("");
  if (connected) {
    try {
      String[] theseTopics=new String[1];
      int[] theseQoS=new int[1];
      theseTopics[0]=topic;
      theseQoS[0]=qos;
synchronized (this) {
        if (sub) {
          writeLogln("  --> SUBSCRIBE,        TOPIC:" + topic + ", Requested QoS:"+ qos);
        }
 else {
          writeLogln("  --> UNSUBSCRIBE,      TOPIC:" + topic);
        }
      }
      if (sub) {
        mqtt.subscribe(theseTopics,theseQoS);
      }
 else {
        mqtt.unsubscribe(theseTopics);
      }
    }
 catch (    Exception ex) {
      setTitleText("MQTT subscription exception caught !");
      JOptionPane.showMessageDialog(frame,ex.getMessage(),"MQTT Subscription Exception",JOptionPane.ERROR_MESSAGE);
    }
  }
 else {
    setTitleText("MQTT client not connected !");
  }
}

public void subscription ( String topic , int qos , boolean sub ) { setTitleText ( "" ) ; if ( connected ) { try { String [ ] theseTopics = new String [ 1 ] ; int [ ] theseQoS = new int [ 1 ] ; theseTopics [ 0 ] = topic ; theseQoS [ 0 ] = qos ; synchronized ( this ) { if ( sub ) { writeLogln ( "  --> SUBSCRIBE,        TOPIC:" + topic + ", Requested QoS:" + qos ) ; } else { writeLogln ( "  --> UNSUBSCRIBE,      TOPIC:" + topic ) ; } } if ( sub ) { mqtt . subscribe ( theseTopics , theseQoS ) ; } else { mqtt . unsubscribe ( theseTopics ) ; } } catch ( Exception ex ) { setTitleText ( "MQTT subscription exception caught !" ) ; JOptionPane . showMessageDialog ( frame , ex . getMessage ( ) , "MQTT Subscription Exception" , JOptionPane . ERROR_MESSAGE ) ; } } else { setTitleText ( "MQTT client not connected !" ) ; } }
this method is called when either the subscribe or unsubscribe buttons are pressed . it performs the mqtt subscribe or unsubscribe and writes an entry in the history log if the history window is open . < br > any exceptions are caught and displayed in a dialog box .
