Skip to content

Console & ConsoleObserver

Pablo Klaschka edited this page Feb 3, 2017 · 2 revisions

What these classes do

These classes were implemented to make it easier to print informations to the console. Also, they enable you to not print the text to the console, but to save them and notify "ConsoleObserver"-Objects with the new text, if something gets printed to the console, so that you could for example set up a textarea in a gui to be your console.

How to use them

The Console

The Console-Class has a few simple static methods. They will be explained here:

Attributes:

  • private static int indentionLevel is the level of indention used when calling printlnIndented([...]).
  • private static printingToConsole determines, whether the print methods are outputting the text to the actual console via System.out.print().
  • private static String consoleText is where all lines printed will be stored in.
  • private static ArrayList<ConsoleObservers> observers is a list of objects implementing the class ConsoleObserver (see below), which will be notified, if something gets printed.

Methods:

static Console.print(Object object)

This method simply adds the String given by object.toString() to the console text (and, if printingToConsole is true, to the actual console) (this will from here on be reffered to as 'printing') without generating a new line or indenting.

static Console.println(Object object)

This method simply prints the String given by object.toString() after a generated new line (via '\n').

static Console.printlnIndented(Object object)

This method simply prints the String given by object.toString() after a generated new line (via '\n').

Clone this wiki locally