reformatted

This commit is contained in:
Pratik Shelarkar 2023-12-03 01:50:13 +05:30
parent cefe159ce0
commit 37222e2785
1 changed files with 26 additions and 23 deletions

View File

@ -26,32 +26,35 @@ import javax.swing.JTextArea;
/** PrintStream for text areas */ /** PrintStream for text areas */
public final class TextAreaPrintStream extends PrintStream { public final class TextAreaPrintStream extends PrintStream {
private final JTextArea textArea; private final JTextArea textArea;
public TextAreaPrintStream(JTextArea textArea) { public TextAreaPrintStream(JTextArea textArea) {
super(new OutputStream() { super(
@Override new OutputStream() {
public void write(int b) throws IOException { @Override
textArea.append(String.valueOf((char) b)); public void write(int b) throws IOException {
} textArea.append(String.valueOf((char) b));
}
@Override @Override
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
String s = new String(b, off, len, StandardCharsets.UTF_8); String s = new String(b, off, len, StandardCharsets.UTF_8);
textArea.append(s); textArea.append(s);
} }
}, false, StandardCharsets.UTF_8); },
false,
StandardCharsets.UTF_8);
this.textArea = textArea; this.textArea = textArea;
} }
@Override @Override
public void flush() { public void flush() {
textArea.repaint(); // Optional: Repaint the text area after appending text textArea.repaint(); // Optional: Repaint the text area after appending text
clear(); clear();
} }
public void clear() { public void clear() {
textArea.setText(""); textArea.setText("");
} }
} }