⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 20-5.txt

📁 Javascript语言开发经典教程开发
💻 TXT
字号:
import netscape.javascript.JSObject;    // These are the classes we'll use.import java.applet.Applet;import java.io.OutputStream;// An output stream that sends HTML text to a newly created web browser window.public class HTMLOutputStream extends OutputStream{    JSObject main_window;        // The initial browser window    JSObject window;             // The new window we create    JSObject document;           // The document of that new window    static int window_num = 0;   // Used to give each new window a unique name    // To create a new HTMLOutputStream, you must specify the applet that    // will use it (this specifies a browser window) and the desired size    // for the new window.    public HTMLOutputStream(Applet applet, int width, int height)    {        // Get main browser window from the applet with JSObject.getWindow().        main_window = JSObject.getWindow(applet);        // Use JSObject.eval() to create a new window.        window = (JSObject)            main_window.eval("self.open(''," +                             "'HTMLOutputStream" + window_num++ + "'," +                             "'menubar,status,resizable,scrollbars," +                             "width=" + width + ",height=" + height + "')");        // Use JSObject.getMember() to get the document of this new window.        document = (JSObject) window.getMember("document");        // Then use JSObject.call() to open this document.        document.call("open", null);    }    // This is the write() method required for all OutputStream subclasses.    public void write(byte[] chars, int offset, int length)    {        // Create a string from the specified bytes.        String s = new String(chars, 0, offset, length);        // Store the string in an array for use with JSObject.call().        Object[] args = { s };        // Check to see if the window has been closed.        boolean closed = ((Boolean)window.getMember("closed")).booleanValue();        // If not, use JSObject.call() to invoke document.write().        if (!closed) document.call("write", args);    }    // Here are two variants on the above method, also required.    public void write(byte[] chars) { write(chars, 0, chars.length); }    public void write(int c) { byte[] chars = {(byte)c}; write(chars, 0, 1); }    // When the stream is closed, use JSObject.call() to call Document.close.    public void close() { document.call("close", null); }    // This method is unique to HTMLOutputStream. If the new window is    // still open, use JSObject.call() to invoke Window.close() to close it.    public void close_window()    {        boolean closed = ((Boolean)window.getMember("closed")).booleanValue();        if (!closed) window.call("close", null);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -