-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.java
42 lines (32 loc) · 959 Bytes
/
Logger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.awt.event.*;
import javax.swing.*;;
/**
* This class handles the output of the user input and system messages either on the console or a JTextArea
*
* @author 162224
* @version 2
*/
public class Logger{
private final static String newline = "\n";
public static Boolean _toConsole = false;
private static JTextArea _text;
/**
* The Logger is set on game setup - either by providing a JText area or null to play on the console
*/
public static void setLogger(JTextArea text){
if (_text != null) {return;}
_text = text;
_toConsole = text == null;
}
/**
* Output of the user message on console or JTextArea
*/
public static void Log(String msg){
if (_toConsole){
System.out.println(msg + newline);
}
else {
_text.setText(_text.getText() + msg + newline);
}
}
}