栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用SwingExplorer浏览Applet内容?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用SwingExplorer浏览Applet内容?

可以提供一种基本的小应用程序 存根 对于在一帧被托管的小应用程序(一个桌面应用程序。)。applet 上下文的
几种方法很容易在应用程序中重现。其他的要么更难,不容易实现,要么与基于桌面的applet不相关。

此示例可以作为嵌入HTML的applet或applet查看器运行,也可以作为嵌入桌面组件的applet运行(特别是a,

JOptionPane
因为代码较短)。

该示例改编自其中OP对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);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/419707.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号