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

📄 pingthread.java

📁 network Programming Project 用NetBeans写的有界面的PING命令程序,程序中用的线程.
💻 JAVA
字号:
/*
 * PingThread.java
 *
 * Created on 2006年5月12日, 下午10:33
 *
 * 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 PingThread extends Thread{
    
    private String Host;
    private JTextArea Parea;
    
    /** Creates a new instance of PingThread */
    public PingThread(String Host,JTextArea Parea){
        this.Host=Host;
        this.Parea=Parea;
        }    

    public void run(){             
        try {
//            FileWriter fw;
            Parea.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");}
//            fw=new FileWriter("text.txt");
//            fw.write(new String(content.append(oneLine+"\n")));
//            fw.close();
            Parea.setText(new String(content));
            
            // display this oneLine String to the corresponding JTextArea
            }
        catch (Exception e) {
            this.doResultLine("Fail to ping the host!");
            }        
    }
    private void doResultLine(String string) {
        throw new UnsupportedOperationException("Not yet implemented");
    }    
}

⌨️ 快捷键说明

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