JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.
And here is my version of your binaryToText
private static String binaryToText(String input) {
if (input.length() % 8 != 0) {
throw new IllegalArgumentException("input must be a multiple of 8");
}
StringBuilder result = new StringBuilder();
for (int i = 0; i <input.length(); i+=8) {
int charCode = Integer.parseInt(input.substring(i,i+8), 2);
result.append((char) charCode);
}
return result.toString();
}
and the textToBinary
private static String textToBinary(String input) {
StringBuilder binResult = new StringBuilder();
for (byte ch : input.getBytes()) {
String binary = Integer.toBinaryString(ch);
switch (binary.length()) {
case 4:
binResult.append("0000").append(binary);
break;
case 6:
binResult.append("00").append(binary);
break;
case 7:
binResult.append("0").append(binary);
break;
default:
binResult.append(binary);
}
}
return binResult.toString();
}