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

📄 tracertthread.java

📁 network Programming Project 用NetBeans写的有界面的PING命令程序,程序中用的线程.
💻 JAVA
字号:
/*
 * TracertThread.java
 *
 * Created on 2006年5月12日, 下午10:36
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package oi0110019;
import java.io.*;
import javax.swing.*;

/**
 *
 * @author SZ
 */
public class TracertThread extends Thread{
   
    private String Host;
    private JTextArea Tarea;
    /** Creates a new instance of TracertThread */
    public TracertThread(String Host ,JTextArea Tarea) {
        this.Host=Host;
        this.Tarea=Tarea;
    }

    public void run(){
        try {
            Tarea.setText(Host);
            Process p;  //java.lang.Process
            // Run your ping or tracert command in an external process
            p = Runtime.getRuntime().exec(Host); 
            InputStream in=p.getInputStream(); // get the output of the process as your input
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String oneLine = br.readLine();
            StringBuffer content = new StringBuffer(); //文件内容
            while ((oneLine = br.readLine()) != null) { //读取文件
            content.append(oneLine+"\n");}
            Tarea.setText(new String(content));
            // display this oneLine String to the corresponding JTextArea
            }        
        catch (Exception e) {
            this.doResultLine("Fail to tracert the host!");
            }
        }

    private void doResultLine(String string) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

}

⌨️ 快捷键说明

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