简体   繁体   English

小程序的主窗口是什么?如何引用它?

[英]What is the main window of an applet called and how do you refer to it?

I'm trying to use Xoverlay and call setWindowHandle, but I need to give a component. 我正在尝试使用Xoverlay并调用setWindowHandle,但我需要提供一个组件。 When I do "run as applet" in eclipse, eclipse creates a small window with the appletviewer. 当我在eclipse中执行“以applet身份运行”时,eclipse将使用appletviewer创建一个小窗口。 I want to know how to get a reference to that window. 我想知道如何获得对该窗口的引用。 I can see that they are adding elements to it here: 我可以看到他们在这里添加元素:

http://download.oracle.com/javase/tutorial/deployment/applet/getStarted.html http://download.oracle.com/javase/tutorial/deployment/applet/getStarted.html

They are simply using add to add it to the main window. 他们只是使用add将其添加到主窗口。 Right now in my application, another window is being spawned that displays video, and I want that video to be displayed in the main applet window so that I can embed the applet in an HTML page and have full control over the window. 现在,在我的应用程序中,正在生成另一个显示视频的窗口,我希望该视频显示在主applet窗口中,以便可以将applet嵌入HTML页面并完全控制该窗口。

I've tried using 'root pane', but then I get this error: 我尝试使用“根窗格”,但随后出现此错误:

java.lang.IllegalArgumentException: Component must be a native window

EDIT: By request, here is my code (There is a comment at the line in question): 编辑:根据要求,这是我的代码(有问题的那一行有注释):

import java.applet.Applet;
import java.awt.*;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.*;

import org.gstreamer.*;
import org.gstreamer.elements.PlayBin2;
import org.gstreamer.interfaces.XOverlay;
import org.gstreamer.lowlevel.GstXOverlayAPI;

public class VideoPlayer extends JApplet {
    public void init() {
        Gst.init();
        final PlayBin2 playbin = new PlayBin2("VideoPlayer");
        URI uri = null;
        try 
        {
            uri = new URI("udp://239.1.1.1:51002");
        } 
        catch (URISyntaxException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        playbin.setURI(uri);
        //System.setProperty("apple.awt.graphics.UseQuartz", "false"); 
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                public void run() {
                    Element videosink = ElementFactory.make("xvimagesink", "imagesink");
                    videosink.set("qos", "false");
                    videosink.set("sync", "false");
                    playbin.setVideoSink(videosink);
                    playbin.setState(State.PLAYING);
                    XOverlay.wrap(videosink).setWindowHandle(rootPane); // I need the handle to the main window here
                }
            });
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Gst.main();
        playbin.setState(State.NULL);
    }
}

尝试使用getRootPane()或从JApplet切换到Applet并使用getParent()

XOverlay.wrap(videosink).setWindowHandle(getRootPane()|getParent());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM