如何从 NetBeans 中的“输出”选项卡获取输入

发布于 2024-11-27 12:29:14 字数 1270 浏览 1 评论 0原文

我创建了一个“输出”选项卡,我想监听用户的输入(以执行类似聊天的组件)。当然,您无法预测用户何时打字。

我找到了 org.jivesoftware.smack.util 包以及相关的 ObservableReader 和 ReaderListener 应该可以解决问题,但我错过了一些东西并且无法弄清楚......还没有。

这是我的代码:

/*
 * Enable/create the tabs we need for the component
 */
package sample.component;

import com.dreamer.outputhandler.OutputHandler;
import org.jivesoftware.smack.util.ObservableReader;
import org.jivesoftware.smack.util.ReaderListener;
import org.openide.modules.ModuleInstall;

/**
 * Manages a module's lifecycle. Remember that an installer is optional and
 * often not needed at all.
 */
public class Installer extends ModuleInstall implements ReaderListener {

    private final String normal = "Output";

    @Override
    public void restored() {
        OutputHandler.output(normal, "Welcome! Type something below.");
        OutputHandler.setInputEnabled(normal, true);
        ObservableReader reader = new ObservableReader(OutputHandler.getReader(normal));
        reader.addReaderListener(this);
    }

    @Override
    public void read(String read) {
        System.out.println("Read: " + read);
        OutputHandler.output(normal, "You typed: " + read);
    }
}

OutPutHandler 是我创建的一个帮助程序类,用于处理输出选项卡。你可以看到它的源码

有什么想法吗?

I have an Output tab created and I would like to listen for user's input (to do a chat like component). Of course you can't predict when the user is going to type.

I found the org.jivesoftware.smack.util package and the related ObservableReader and ReaderListener that should do the trick, but I'm missing something and can't figure it out... yet.

Here's the code I have:

/*
 * Enable/create the tabs we need for the component
 */
package sample.component;

import com.dreamer.outputhandler.OutputHandler;
import org.jivesoftware.smack.util.ObservableReader;
import org.jivesoftware.smack.util.ReaderListener;
import org.openide.modules.ModuleInstall;

/**
 * Manages a module's lifecycle. Remember that an installer is optional and
 * often not needed at all.
 */
public class Installer extends ModuleInstall implements ReaderListener {

    private final String normal = "Output";

    @Override
    public void restored() {
        OutputHandler.output(normal, "Welcome! Type something below.");
        OutputHandler.setInputEnabled(normal, true);
        ObservableReader reader = new ObservableReader(OutputHandler.getReader(normal));
        reader.addReaderListener(this);
    }

    @Override
    public void read(String read) {
        System.out.println("Read: " + read);
        OutputHandler.output(normal, "You typed: " + read);
    }
}

OutPutHandler is a helper class I created to handle the output tabs. You can see its source here

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面犯桃花 2024-12-04 12:29:14

终于明白了!它是上述代码与 this 论坛帖子和此类的混合:org.jivesoftware.smack .util.ObservableReader 和 org.jivesoftware.smack.util.ReaderListener。请参阅此处的常见问题解答

Finally got it! It was a mix of the above code with this forum post and this classes: org.jivesoftware.smack.util.ObservableReader and org.jivesoftware.smack.util.ReaderListener. See the FAQ here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文