?
-
I have a class A that has a method that does something and then prints
to a console:
public class A {
public A() {
...
}
public void handleMessage(Message message) {
String command = message.getCommand();
if (command.equals("A")) {
handleA(message);
} else if (command.equals("B")) {
handleB(message);
...
...
...
} else if (command.equals("Z")) {
handleZ(message);
}
}
protected void handleA(Message message) {
... do stuff
System.out.println(text);
}
protected void handleB(Message message) {
... do other stuff
System.out.println(text1);
}
...
...
protected void handleZ(Message message) {
... do some other stuff
System.out.println(text);
}
}
'text', 'text1', ... 'text2' are varying text based on
message.getParameters().
now i would like to print the 'text', 'text1', ... 'text2' inside a
JTextPane and use different colors for the text.
One way I can think of is to subclass A:
public class GUIA extends A {
public GUIA() {
...
}
public void handleMessage(Message message) {
String command = message.getCommand();
if (command.equals("A")) {
handleA(message);
} else if (command.equals("B")) {
handleB(message);
...
...
...
} else if (command.equals("Z")) {
handleZ(message);
}
}
protected void handleA(Message message) {
super.handleA(message);
jTextPane.insertString(...);
}
protected void handleB(Message message) {
super.handleB(message);
jTextPane.insertString(...);
}
...
...
protected void handleZ(Message message) {
super.handleZ(message);
jTextPane.insertString(...);
}
}
Three questions:
1) Is it supposed to be subclassed?
2) If no, what is the correct way?
3) If yes, how do I 'silenced' the System.out.println() or redirect it etc.
Thank you in advance.
to a console:
public class A {
public A() {
...
}
public void handleMessage(Message message) {
String command = message.getCommand();
if (command.equals("A")) {
handleA(message);
} else if (command.equals("B")) {
handleB(message);
...
...
...
} else if (command.equals("Z")) {
handleZ(message);
}
}
protected void handleA(Message message) {
... do stuff
System.out.println(text);
}
protected void handleB(Message message) {
... do other stuff
System.out.println(text1);
}
...
...
protected void handleZ(Message message) {
... do some other stuff
System.out.println(text);
}
}
'text', 'text1', ... 'text2' are varying text based on
message.getParameters().
now i would like to print the 'text', 'text1', ... 'text2' inside a
JTextPane and use different colors for the text.
One way I can think of is to subclass A:
public class GUIA extends A {
public GUIA() {
...
}
public void handleMessage(Message message) {
String command = message.getCommand();
if (command.equals("A")) {
handleA(message);
} else if (command.equals("B")) {
handleB(message);
...
...
...
} else if (command.equals("Z")) {
handleZ(message);
}
}
protected void handleA(Message message) {
super.handleA(message);
jTextPane.insertString(...);
}
protected void handleB(Message message) {
super.handleB(message);
jTextPane.insertString(...);
}
...
...
protected void handleZ(Message message) {
super.handleZ(message);
jTextPane.insertString(...);
}
}
Three questions:
1) Is it supposed to be subclassed?
2) If no, what is the correct way?
3) If yes, how do I 'silenced' the System.out.println() or redirect it etc.
Thank you in advance.