【问题标题】:How Do I Get Output From My NsLookup Program into JTextArea in Seperate Program如何从我的 NsLookup 程序中获取输出到单独程序中的 JTextArea
【发布时间】:2014-11-05 17:58:48
【问题描述】:

我只是想知道如何将单独的 NsLookup 程序的输出输入到我的 NsLookupGUI 程序中的 TextArea 中?

我有一个 ActionListener;

private class buttonPressed implements ActionListener {
        public void actionPerformed(ActionEvent a) {
                getText = userInputBox.getText();

        lookup.resolve(getText);

        results.append(getText + "\n"); 
        }

调用 Nslookup 类。但是,输出显示在终端而不是 TextArea 中。

下面这段代码是我的 NsLookup 程序;

public class NsLookup {

    private InetAddress iNet = null;

    public void resolve(String hostName) {
    try {
    iNet = InetAddress.getByName(hostName);

    System.out.println("Host Name: " + iNet.getHostName());
    System.out.println("IP Address is: " + iNet.getHostAddress());
    }

提前致谢!

【问题讨论】:

    标签: java swing user-interface nslookup


    【解决方案1】:

    使用文本区域对象的setText() 方法。

    textareaobj.setText(...)

    【讨论】:

      【解决方案2】:

      如果需要,您还可以将 System.out 重新分配给打印到文本区域的自定义 OutputStream。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多