如何使用SwingExplorer导航Applet的内容? [英] How can I use SwingExplorer to navigate Applet content?

查看:240
本文介绍了如何使用SwingExplorer导航Applet的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有从这个网站 http://www.swingexplorer.com/ 是用于导航SwingExplorer工具摆动内容,但我怎么将它应用于小程序吗?,尤其是如果我要整合它Eclipse的插件如何配置运行配置?

There is SwingExplorer tool from this site http://www.swingexplorer.com/ that used to navigate swing content but how do I apply it to Applet?,especially if I want to integrate it to eclipse-plugin how do I configure the running configuration?

我猜你需要提供您要运行AppletViwer小程序的参数,让SwingExplorer导航的appletviewer(这反过来又运行Applet类),但我不知道如何将此类参数传递到AppletViwer,任何人都可以解释我是如何做到这一点?

I guess that you need to supply the parameter of the applet that you want to run to AppletViwer and let the SwingExplorer navigate the AppletViewer(which in turn run your applet class) but i don't know how to pass such parameter to AppletViwer,Can anyone explain me how to do this?

请注意,仅仅在小程序的顶部创建新的框架,并让它运行如常Swing应用程序不会做,因为它需要类似浏览器的环境中运行。

Note that simply create new frame on top of applet and let it run as usual Swing application will not do because it need to be operated in browser-like environment.

推荐答案

它的可以提供一个基本的小程序的存根的对于在一帧被托管的一个applet (桌面应用程序)。小程序的几种方法的背景的很容易在应用程序中重现。其他人要么是很难的,不切实际的轻松实现,或不相关的桌面基础小程序。

It is possible to provide a basic applet stub for an applet that is being hosted in a frame (a desktop app.). Several methods of the applet context are easy to reproduce in an application. The others are either harder, impractical to implement easily, or not relevant to a desktop based applet.

这个例子可以运行,可为嵌入在HTML中的小应用程序或applet浏览器,或者嵌入在桌面组件(特别是一个的JOptionPane 自$ C的小程序$ c是短)。

This example can be run as either an applet embedded in HTML or the applet viewer, or as an applet embedded in a desktop component (specifically a JOptionPane since the code is shorter).

这个例子改编自之一,其中OP更感兴趣的是小程序的参数。该版本还增加了对报告的文档和code基地的支持。

The example was adapted from one in which the OP was more interested in the applet parameters. This version also adds support for reporting the document and code base.

/*
<applet code='DesktopEmbeddedApplet' width='400' height='100'>
<param name='param' value='embedded in applet viewer or the browser'>
</applet>
*/
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.io.File;
import java.net.URL;
import java.util.HashMap;

public class DesktopEmbeddedApplet extends JApplet {

    public void init() {
        setLayout(new GridLayout(0,1));
        String param = getParameter("param");
        System.out.println("parameter: " + param);
        add(new JLabel(param));
        add(new JLabel("" + getDocumentBase()));
        add(new JLabel("" + getCodeBase()));
    }

    public static void main(String[] args) {
        ApplicationAppletStub stub = new ApplicationAppletStub();
        stub.addParameter("param", "embedded in application");
        DesktopEmbeddedApplet pa = new DesktopEmbeddedApplet();
        pa.setStub(stub);

        pa.init();
        pa.start();
        pa.setPreferredSize(new java.awt.Dimension(400,100));
        JOptionPane.showMessageDialog(null, pa);
    }
}

class ApplicationAppletStub implements AppletStub {

    HashMap<String,String> params = new HashMap<String,String>();

    public void appletResize(int width, int height) {}
    public AppletContext getAppletContext() {
        return null;
    }

    public URL getDocumentBase() {
        URL url = null;
        try {
            url = new File(".").toURI().toURL();
        } catch(Exception e) {
            System.err.println("Error on URL formation!  null returned." );
            e.printStackTrace();
        }
        return url;
    }

    public URL getCodeBase() {
        URL url = null;
        try {
            url = new File(".").toURI().toURL();
        } catch(Exception e) {
            System.err.println("Error on URL formation!  null returned." );
            e.printStackTrace();
        }
        return url;
    }

    public boolean isActive() {
        return true;
    }

    public String getParameter(String name) {
        return params.get(name);
    }

    public void addParameter(String name, String value) {
        params.put(name, value);
    }
}

这篇关于如何使用SwingExplorer导航Applet的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆