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

📄 guioutput.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.ui.awt;

import java.io.OutputStream;
import java.io.PrintStream;
import java.awt.TextArea;

/**Simple OutputStream extension for redirecting the System.out to a specified
 * TextArea.*/
public class GUIOutput extends OutputStream
{
	private static PrintStream redirectedOut;
	private static TextArea outputTextArea;
	private static PrintStream oldPrintStream;

	/**<ol><li>Creates a new <code>PrintStream</code> object to redirect the standard <code>System.out</code> object</li><li>Does the redirection</li></ol>*/
	public GUIOutput(TextArea _outputTextArea)
	{
		super();
		outputTextArea = _outputTextArea;
		redirectedOut = new PrintStream(this);
		oldPrintStream = System.out;
		System.setOut(redirectedOut);
	}

	/**<ol><li>Covert the specified <code>int</code> to an array of bytes</li><li>Convert the array of bytes to a String</li><li>Calls to <code>write(String s)</code> method</li></ol>*/
	public void write(int b)
	{
		byte b8[] = new byte[1];
		b8[0] = (new Integer(b)).byteValue();
		write(new String(b8));
	}

	/**<ol><li>Covert the specified array of ints to an array of bytes</li><li>Convert the array of bytes to a String</li><li>Calls to <code>write(String s)</code> method</li></ol>*/
	public void write(int[] b)
	{
		byte b8[] = new byte[b.length];
		for (int i=0; i<b.length; i++) {
			b8[i] = (new Integer(b[i])).byteValue();
		}
		write(new String(b8));
	}

	/**Appends the specified <code>String</code> to the <code>java.awt.TextArea</code> specified at constructor's time*/
	public void write(String s)
	{
		outputTextArea.append(s);
	}

	/**Restores the original <code>System.out</code> PrintStream.*/
	public void dispose()
	{
		System.setOut(oldPrintStream);
	}
}

⌨️ 快捷键说明

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