Create a static final class and static methods and use it through out the application. Static method can be directly called without instantiating the class.
Java Make Own System.out
-
29-06-2022 - |
Question
Is there any way to make my own System.out? I want to have a class "MyConsole" with an attribute out (PrintWriter) and send from all classes txt messages that will be printed in a JTextArea (like System.out print all messages in the console) without make a instance of it in all classes or pass it in the attributes
Solution 2
OTHER TIPS
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
Why don't you just make your own class that extends JTextArea
and write a method to do what you want? Something like:
public class MyTextArea extends JTextArea {
public void println() {
//add text to the textarea
}
}
If you don't need your method to have name println
you can just use the append
method, which already exists in the JTextArea
:
textArea.append(myString+"\n");
I use this open source Message Console in java. It's simple to use.