import java.awt.*; import java.awt.event.*; import java.io.*; /** * * * This class implements a simple console window, conceptually a replacement for * reading/writing to System.out and System.in. * * The intended use is as a ConsoleWindow for messages and simple command * processing. * */ public class ConsoleWindow extends java.awt.Frame implements WindowListener { private KeyboardBuffer area; private InputStreamReader input; private BufferedReader bufferedinput; private PrintWriter output; private boolean dead = false; String fname; int fstyle; int fsize; static int default_bufferchars = 10000; int bufferchars; PrintWriter out; BufferedReader in; public ConsoleWindow (String title) { this(title, default_bufferchars); out = this.PrintWriter(); in = this.BufferedReader(); } public ConsoleWindow (String title, int bufferchars) { // Initialize this.bufferchars = bufferchars; area = new KeyboardBuffer("",30,80,bufferchars); fname = "Courier"; fstyle = Font.PLAIN; fsize = 12; // Show window area.setFont(new Font(fname, fstyle, fsize)); setTitle(title); add("Center", area); pack(); show(); addWindowListener(this); } // Handle system event public void dispose () { dead=true;//System.out.println("declared dead"); area.die(); super.dispose(); } public PrintWriter PrintWriter () { if(output==null) { output = area.PrintWriter(); } return(output); } /** * get a InputStream corresponding to the typein area if this window. * Note that the input from the InputStream will be line buffered, so no * input is available from incomplete lines. * */ public InputStreamReader InputStreamReader () { if(input==null) { input = area.InputStreamReader();} return(input); } /** * get a BufferedReader corresponding to the typein area if this window. * Note that the input from the BufferedReader will be line buffered, so no * input is available from incomplete lines. * */ public BufferedReader BufferedReader () { if(bufferedinput==null) { bufferedinput = new BufferedReader(InputStreamReader()); } return(bufferedinput); } /** * returns true if the console window has been activated and is visible */ public boolean Active () { return(!dead); } /** * wait until the console window has been closed */ public void Wait_For_Finish () throws InterruptedException { while(Active()) { Thread.sleep(1000); } } /** * unconditionally wait until the console window has been closed */ public void Always_Wait_For_Finish () { try {Wait_For_Finish(); } catch (InterruptedException err) {} } /* handle window events */ public void windowActivated(WindowEvent ev) {} public void windowDeactivated(WindowEvent ev) {} public void windowClosed(WindowEvent ev) { //System.exit(0); } public void windowClosing(WindowEvent ev) { //dispose(); } public void windowDeiconified(WindowEvent ev) {} public void windowIconified(WindowEvent ev) {} public void windowOpened(WindowEvent ev) {} }