package CSLib;
import java.awt.*;
/**
* OutputBox is a closable frame that holds textual output.
* It mimics Java's java.lang.System.out, which is
* a java.io.PrintStream.
*
* @see java.io.PrintStream
* @see java.awt.TextArea
*
* @author M. Dennis Mickunas
*/
public class OutputBox extends ClosableFrame {
/**
* the area where output is printed
*/
private TextArea outputArea;
private Font font;
private static final int WIDTH = 550;
private static final int HEIGHT = 380;
/**
* Constructs an OutputBox with a default title.
*/
public OutputBox () {
this("OutputBox");
}
/**
* Constructs an OutputBox with a specific title.
*
* @param title the specific String to use as the title
*/
public OutputBox (String title) {
super(title);
setResizable(true);
outputArea = new TextArea();
add(outputArea);
setSize(WIDTH, HEIGHT);
setVisible(true);
validate();
setFont(new Font("Courier", Font.PLAIN, 12));
}
/**
* Erases the text in the OutputBox.
*/
public void clear () { outputArea.setText(""); }
/**
* Changes the font for subsequent printing.
*
* @param font the specific Font to change to.
*/
public void setFont (Font font) {
outputArea.setFont(font);
this.font = font;
}
/**
* Prints a string. The string printed is just what would be
* printed by java.lang.System.out.print(String).
*
* @param text the String to be printed
*/
public void print (String text) { outputArea.append(text); }
/**
* Prints an integer. The string printed is just what would be
* printed by java.lang.System.out.print(int).
*
* @param number the int to be printed
*/
public void print (int number) { print("" + number); }
/**
* Prints a floating-point number. The string printed is just what would be
* printed by java.lang.System.out.print(float).
*
* @param number the float to be printed
*/
public void print (float number) { print("" + number); }
/**
* Prints a double-precision floating-point number. The string
* printed is just what would be printed by
* java.lang.System.out.print(double).
*
* @param number the double to be printed
*/
public void print (double number) { print("" + number); }
/**
* Prints a boolean value. The string printed is just what would be
* printed by java.lang.System.out.print(boolean).
*
* @param b the boolean to be printed
*/
public void print (boolean b) { print("" + b); }
/**
* Prints a character. The string printed is just what would be
* printed by java.lang.System.out.print(char).
*
* @param c the char to be printed
*/
public void print (char c) { print("" + c); }
/**
* Prints a long integer. The string printed is just what would be
* printed by java.lang.System.out.print(long).
*
* @param number the long to be printed
*/
public void print (long number) { print("" + number); }
/**
* Prints a string buffer. The string printed is just what would be
* printed by java.lang.System.out.print(StringBuffer).
*
* @param strBuf the StringBuffer to be printed
* @see java.lang.StringBuffer#toString()
*/
public void print (StringBuffer strBuf) { print(strBuf.toString()); }
/**
* Terminates the current line by writing a carriage return character
* followed by a newline character.
*/
public void println () { outputArea.append("\n"); }
/**
* Prints a String and then terminates the line. This method
* invokes print(String) and then println().
*
* @param number the String to be printed.
*/
public void println (String text) { print(text); println(); }
/**
* Prints an integer and then terminates the line. This method behaves as
* though it invokes print(int) and then
* println().
*
* @param number the int to be printed.
*/
public void println (int number) { println("" + number); }
/**
* Prints a float and then terminates the line. This method behaves as
* though it invokes print(float) and then
* println().
*
* @param number the float to be printed.
*/
public void println (float number) { println("" + number); }
/**
* Prints a double and then terminates the line. This method behaves as
* though it invokes print(double) and then
* println().
*
* @param number the double to be printed.
*/
public void println (double number) { println("" + number); }
/**
* Prints a boolean and then terminates the line. This method behaves as
* though it invokes print(boolean) and then
* println().
*
* @param b the boolean to be printed
*/
public void println (boolean b) { println("" + b); }
/**
* Print a character and then terminate the line. This method behaves as
* though it invokes print(char) and then
* println().
*
* @param c the char to be printed.
*/
public void println (char c) { println("" + c); }
/**
* Prints a long and then terminates the line. This method behaves as
* though it invokes print(long) and then
* println().
*
* @param number The long to be printed.
*/
public void println (long number) { println("" + number); }
/**
* Prints a string buffer and then terminates the line. This method behaves
* as though it invokes print(StringBuffer) and then
* println().
*
* @param strBuf the StringBuffer to be printed
*/
public void println (StringBuffer strBuf) { println(strBuf.toString()); }
}