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

HTML for Java组件应如何参考资源?

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

HTML for Java组件应如何参考资源?

通过相对
引用链接资源(例如CSS或图像)的Jar文件中的HTML即可正常工作。

例如
本示例从
Jar中加载HTML(具有相对于图像的引用)。

import javax.swing.*;import java.net.URL;class ShowHtml {    public static void main(String[] args) {        final String address = "jar:http://pspre.org/jh/hs/object.jar!/popup_contents.html";        SwingUtilities.invokeLater(new Runnable() { public void run() {     try {         URL url = new URL(address);         JEditorPane jep = new JEditorPane(url);         Jframe f = new Jframe("Show HTML in Jar");         f.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);         f.add(new JScrollPane(jep));         f.pack();         f.setSize(400,300);         f.setLocationByPlatform(true);         f.setVisible(true);     } catch(Exception e) {         e.printStackTrace();     } }        });    }}

Screenshot

HTML

正在加载的HTML。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><!--        *        Copyright (C) 1997  Sun Microsystems, Inc *         All rights reserved. *          Notice of copyright on this source pre  *          product does not indicate publication.  *  * RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by  * the U.S. Government is subject to restrictions as set forth  * in subparagraph (c)(1)(ii) of the Rights in Technical Data * and Computer Software Clause at DFARS 252.227-7013 (Oct. 1988)  * and FAR 52.227-19 (c) (June 1987). * *    Sun Microsystems, Inc., 2550 Garcia Avenue, *    Mountain View, California 94043. *--><HTML><HEAD><TITLE>Editing Project Attributes</TITLE></HEAD><BODY BGCOLOR="#ffffff"><IMG SRC="images/popup_icon.gif" width="24" height="24"> <b>Popup Window</b><p>Popup windows appear near the location from which they areactivated.  They are not contained in frames and thuscannot be resized or moved by the user.  Popups aredismissed by clicking anywhere in the help viewer.<p>Popup windows can be activated by clicking on a text object, graphic object, or JComponent button.  All three examples areincluded in this demo.<p><A HREF="popup_contents2.html">More...</A></body></html>

E.G. 2

对于动态创建的HTML,JRE可能会将类文件的
位置用作HTML的假定位置。但是,为了消除所有疑问,我们可以在中
指定

base
元素
head

import javax.swing.*;class HtmlUsingbase {    public static void main(String[] args) {        final String htmlContent = "<html>" + "<head>" + "<base href='http://www.gravatar.com/'>" + "</head>" + "<body>" + "<h1>Image path from base</h1>" + "<img src='avatar/a1ab0af4997654345d7a9" + "49877f8037e?s=128&d=identicon&r=PG'" + " width='128' height='128'>" + "</body>" + "</html>";        SwingUtilities.invokeLater(new Runnable() { public void run() {     JLabel label = new JLabel(htmlContent);     JOptionPane.showMessageDialog(null, label); }        });    }}


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

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

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