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

📄 appoutputcapture.java

📁 控制台数据截取,(哎,还要打满20个字,麻烦)
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;

public class AppOutputCapture {
		private static Process process;

		public static void main(String[] args) {
				if(args.length == 0) {
		 	System.err.println("用法:java AppOutputCapture " +
				 "<程序名字> {参数1 参数2 ...}");
		 	System.exit(0);
				}

				try {
						// 启动命令行指定程序的新进程
						process = Runtime.getRuntime().exec(args);
				}
				catch(IOException e) {
						System.err.println("创建进程时出错...\n" + e);
						System.exit(1);
				}

				// 获得新进程所写入的流
				InputStream[] inStreams =
						new InputStream[] {
					process.getInputStream(),process.getErrorStream()};
				ConsoleTextArea cta = new
	ConsoleTextArea(inStreams);
				cta.setFont(java.awt.Font.decode("monospaced"));

				JFrame frame = new JFrame(args[0] +
						"控制台输出");

				frame.getContentPane().add(new JScrollPane(cta),
					BorderLayout.CENTER);
				frame.setBounds(50, 50, 400, 400);
				frame.setVisible(true);

				frame.addWindowListener(new WindowAdapter() {
						public void windowClosing(WindowEvent evt) {
								process.destroy();
								try {
										process.waitFor(); // 在Win98下可能被挂起
								}
								catch(InterruptedException e) {}
										System.exit(0);
								}
						});
		} // main()
} // AppOutputCapture

⌨️ 快捷键说明

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