开发者

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 comp开发者_C百科onent. When I do "run as applet" in eclipse, eclipse creates a small window with the 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

They are simply using add to add it to the main window. 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.

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);
    }
}


try using getRootPane() or switch from JApplet to Applet and use getParent()

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜