// Dilip Barman November 24, 1997 // file DebugWindow.java // // I got this idea and copied the core of the code from "Core Java 1.1" vol.1 // pages 598-600 (Sun Microsystems Press, 1997). In an application or // applet under development, define a variable of type DebugWindow - e.g., // static DebugWindow dw = new DebugWindow("MyClass"); // (or you can leave out the string -- DebugWindow();) // then send it the print message with an argument to be printed to the // debugger window - e.g., // dw.print ("Processing event " + event); // import java.awt.*; // Window I/O classes import java.awt.event.*; // Event classes public class DebugWindow extends Frame { private TextArea output = new TextArea(); // simple single message this class understands - append to debug window public void print(Object obj) { output.append ("\n" + obj); } // constructor; create window and make it a visible and closeable frame public DebugWindow () { realConstructor("Debug Window"); } public DebugWindow (Object obj) // if argument, add to title { realConstructor("Debug Window: " + (String) obj); } private void realConstructor (String theTitle) { setTitle (theTitle); output.setEditable (false); output.setText ("[" + theTitle + "]"); add (output, "Center"); setSize (300,300); setLocation (500,300); setBackground (Color.lightGray); setForeground (Color.blue); addWindowListener // close window when user asks it to be closed ( new WindowAdapter() { public void windowClosing (WindowEvent e) { setVisible(false); } } ); show(); } // end constructor } // End DebugWindow class