首页 文章

处理html按钮代号为1的事件

提问于
浏览
0

在表单中我嵌入了WebBrowser组件,其中包含许多用于丰富ui的html内容(主要是表格,按钮) . 点击html按钮可以处理事件吗?

1 回答

  • 0

    当然,看看厨房水槽演示样品 .

    通常只需导航到事件上的URL并实现您自己的 BrowserNavigationCallback 来处理该特定URL的导航 .

    这是来自Kitchen Sink演示通知 setBrowserNavigationCallback 块的代码:

    final WebBrowser wb = new WebBrowser();
        if(wb.getInternal() instanceof BrowserComponent) {
            Button btn = new Button("Add");
            final TextArea content = new TextArea();
            Container north = new Container(new BorderLayout());
            north.addComponent(BorderLayout.CENTER, content);
            north.addComponent(BorderLayout.EAST, btn);
            cnt.addComponent(BorderLayout.NORTH, north);
            content.setHint("Add to web document");
            btn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    ((BrowserComponent)wb.getInternal()).execute("fnc('" + content.getText() + "');");
                }
            });
            ((BrowserComponent)wb.getInternal()).setBrowserNavigationCallback(new BrowserNavigationCallback() {
                public boolean shouldNavigate(String url) {
                    if(url.startsWith("http://sayhello")) {
                        // warning!!! This is not on the EDT and this method MUST return immediately!
                        Display.getInstance().callSerially(new Runnable() {
                            public void run() {
                                ((BrowserComponent)wb.getInternal()).execute("fnc('this was written by Java code!')");
                            }
                        });
                        return false;
                    }
                    return true;
                }
            });
        }
    

相关问题