private void toHexString(){
  String pubText=pubData.getText();
  StringBuffer hexText=new StringBuffer();
  byte[] pubBytes=pubText.getBytes();
  for (int i=0; i < pubBytes.length; i++) {
    int byteValue=pubBytes[i];
    if (byteValue < 0) {
      byteValue+=256;
    }
    if (byteValue < 16) {
      hexText.append("0" + Integer.toHexString(byteValue));
    }
 else {
      hexText.append(Integer.toHexString(byteValue));
    }
  }
  hexDisplay=true;
  pubLabel.setText(PANEL_TITLE + " - hexadecimal display");
  mqttMgr.setTitleText("");
  hexButton.setText("Text");
  pubData.setText(hexText.toString());
}

private void toHexString ( ) { String pubText = pubData . getText ( ) ; StringBuffer hexText = new StringBuffer ( ) ; byte [ ] pubBytes = pubText . getBytes ( ) ; for ( int i = 0 ; i < pubBytes . length ; i ++ ) { int byteValue = pubBytes [ i ] ; if ( byteValue < 0 ) { byteValue += 256 ; } if ( byteValue < 16 ) { hexText . append ( "0" + Integer . toHexString ( byteValue ) ) ; } else { hexText . append ( Integer . toHexString ( byteValue ) ) ; } } hexDisplay = true ; pubLabel . setText ( PANEL_TITLE + " - hexadecimal display" ) ; mqttMgr . setTitleText ( "" ) ; hexButton . setText ( "Text" ) ; pubData . setText ( hexText . toString ( ) ) ; }
this method reads in the data from the publish text area as text characters and converts them into hex characters ( i . e . every character read is represented as two hex characters ) . it is used when the button saying ' hex ' is pressed indicating that the text data in the data area needs to be converted to a hex representation . < br > the text string read in from the data area is converted into an array of bytes . the integer value of each byte is then converted into a hex string representation and append to the output string buffer . once the entire input string has been processed the output string is written back to the text area .
