public void run(){
  int rc=-1;
  String ipAddr=(String)ipAddress.getSelectedItem();
  String portNum=(String)port.getSelectedItem();
  String connStr="";
  try {
    if (ipAddr.indexOf("://") < 0) {
      connStr="tcp://" + ipAddr + ":"+ portNum;
    }
 else {
      connStr=ipAddr;
    }
    connect(connStr,optionsComp.isPersistenceSelected());
    updateComboBoxList(ipAddress,ipAddr);
    updateComboBoxList(port,portNum);
    connected=true;
    led.setGreen();
    setConnected(true);
  }
 catch (  NumberFormatException nfe) {
    JOptionPane.showMessageDialog(frame,"Invalid port number !","MQTT Connect Exception",JOptionPane.ERROR_MESSAGE);
  }
catch (  MqttException mqe) {
    setTitleText("MQTT connect failed !");
    Throwable e=mqe.getCause();
    String msg="";
    if (e == null) {
      e=mqe;
    }
 else     if (mqe.getMessage() != null) {
      msg+=mqe.getMessage() + "\n";
    }
    msg+=e;
    JOptionPane.showMessageDialog(frame,msg,"MQTT Connect Exception",JOptionPane.ERROR_MESSAGE);
    e.printStackTrace();
  }
catch (  Exception ex) {
    setTitleText("MQTT connect failed !");
    JOptionPane.showMessageDialog(frame,ex,"MQTT Connect Exception",JOptionPane.ERROR_MESSAGE);
    ex.printStackTrace();
  }
  if (!connected) {
    led.setRed();
    setConnected(false);
  }
synchronized (this) {
    if (connected) {
      writeLogln("WebSphere MQ Telemetry transport connected to " + mqtt.getServerURI());
    }
 else {
      writeLogln("ERROR:WebSphere MQ Telemetry transport failed to connect to " + connStr);
    }
  }
}

public void run ( ) { int rc = - 1 ; String ipAddr = ( String ) ipAddress . getSelectedItem ( ) ; String portNum = ( String ) port . getSelectedItem ( ) ; String connStr = "" ; try { if ( ipAddr . indexOf ( "://" ) < 0 ) { connStr = "tcp://" + ipAddr + ":" + portNum ; } else { connStr = ipAddr ; } connect ( connStr , optionsComp . isPersistenceSelected ( ) ) ; updateComboBoxList ( ipAddress , ipAddr ) ; updateComboBoxList ( port , portNum ) ; connected = true ; led . setGreen ( ) ; setConnected ( true ) ; } catch ( NumberFormatException nfe ) { JOptionPane . showMessageDialog ( frame , "Invalid port number !" , "MQTT Connect Exception" , JOptionPane . ERROR_MESSAGE ) ; } catch ( MqttException mqe ) { setTitleText ( "MQTT connect failed !" ) ; Throwable e = mqe . getCause ( ) ; String msg = "" ; if ( e == null ) { e = mqe ; } else if ( mqe . getMessage ( ) != null ) { msg += mqe . getMessage ( ) + "\n" ; } msg += e ; JOptionPane . showMessageDialog ( frame , msg , "MQTT Connect Exception" , JOptionPane . ERROR_MESSAGE ) ; e . printStackTrace ( ) ; } catch ( Exception ex ) { setTitleText ( "MQTT connect failed !" ) ; JOptionPane . showMessageDialog ( frame , ex , "MQTT Connect Exception" , JOptionPane . ERROR_MESSAGE ) ; ex . printStackTrace ( ) ; } if ( ! connected ) { led . setRed ( ) ; setConnected ( false ) ; } synchronized ( this ) { if ( connected ) { writeLogln ( "WebSphere MQ Telemetry transport connected to " + mqtt . getServerURI ( ) ) ; } else { writeLogln ( "ERROR:WebSphere MQ Telemetry transport failed to connect to " + connStr ) ; } } }
invoked by actionperformed when connect is pressed . this allows actionperformed to return and paint the window . this thread then does the mqtt connect to the broker . < br > this method also ensures that the led colour is set correctly and writes an entry to the history dialog if it is open .
