logo
down
shadow

Updating my textArea whilst in a while loop


Updating my textArea whilst in a while loop

By : user2953314
Date : November 20 2020, 01:01 AM
I hope this helps you . You need to respect Swing threading rules which to summarize too briefly means that all running tasks, such as waiting for and capturing your data, should be done in a background thread, and all Swing calls should be done on the Swing event thread. Use a SwingWorker to help you do this.
Please check out Concurrency in Swing to see a tutorial with all the gory details.
code :
private class MySwingWorker extends SwingWorker<Void, String> {
  private byte[] buffer = new byte[2000];

  @Override
  protected Void doInBackground() throws Exception {
     while (true) {
        DatagramPacket incoming = new DatagramPacket(buffer, buffer.length);
        serverSocket.receive(incoming);

        String incomingMessage = new String(incoming.getData());
        publish(incomingMessage);
     }
     return null;
  }

  @Override
  protected void process(List<String> chunks) {
     for (String chunk : chunks) {
        textArea.append("Client: " + chunk + "\n");
     }
  }
}


Share : facebook icon twitter icon
Stop an app from updating itself whilst being used

Stop an app from updating itself whilst being used


By : varun ss
Date : March 29 2020, 07:55 AM
seems to work fine You can't stop the update, but you can make sure, there is no corruption, and there is no data lost: Before Update, the application's onPause() callback will be called - time to make sure, the App is in a recoverable state. This might include storing the momentary working set to some temp storage. After update, the app will receive onResume(), where you can load the working set back.
Is there a way to write and retrive code snippets on a textarea whilst not losing the structure?

Is there a way to write and retrive code snippets on a textarea whilst not losing the structure?


By : Yanchao Liang
Date : March 29 2020, 07:55 AM
may help you . You shouldn't do any encoding on the data before storing it. You should only sanitize it to prevent injection. You should encode it for display (mainly use htmlspecialchars on it).
If you are displaying it in another container (not a textarea), you can add the white-space: pre rule to it, or just use
 tags to have it display whitespace as-is. If you are displaying it in a