gpt4 book ai didi

Java 自己制作 System.out

转载 作者:行者123 更新时间:2023-11-30 04:13:52 25 4
gpt4 key购买 nike

有没有办法制作我自己的System.out?我想要一个带有属性 out (PrintWriter) 的类“MyConsole”,并从所有类发送将在 JTextArea 中打印的 txt 消息(如 System.out 打印控制台中的所有消息),而不在所有中创建它的实例类或在属性中传递它

最佳答案

i need something like ex: Console1.out.println(message1) and the message 1 goes only in the JTextArea linked Console1, Console2.out.println(message2) and the message 2 goes only in the JTextArea linked Console2

为什么不创建自己的类来扩展 JTextArea 并编写一个方法来执行您想要的操作?像这样的东西:

public class MyTextArea extends JTextArea {
public void println() {
//add text to the textarea
}
}

如果您不需要方法的名称为 println,您可以只使用 append 方法,该方法已存在于 JTextArea 中:

textArea.append(myString+"\n");

关于Java 自己制作 System.out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18921177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com