How do you open web pages in Java?(你如何在 Java 中打开网页?)
问题描述
有没有一种简单的方法可以在 GUI 的 JPanel 中打开网页?
Is there a simple way to open a web page within a GUI's JPanel?
如果没有,如何使用计算机的默认网络浏览器打开网页?
If not, how do you open a web page with the computer's default web browser?
我希望我可以用不到 20 行代码来做一些事情,并且最多需要创建一个类.20 没有理由,只是希望代码少......
I am hoping for something that I can do with under 20 lines of code, and at most would need to create one class. No reason for 20 though, just hoping for little code...
我打算打开一个游戏指南.该指南是在线的并且有多个页面,但是页面之间是相互链接的,所以我希望我只需要用我的代码调用一个 URL.
I am planning to open a guide to go with a game. The guide is online and has multiple pages, but the pages link to each other, so I am hoping I only have to call one URL with my code.
推荐答案
用默认浏览器打开网页很简单:
Opening a web page with the default web browser is easy:
java.awt.Desktop.getDesktop().browse(theURI);
嵌入浏览器并不容易.JEditorPane 有 一些 HTML 能力(如果我没记错我有限的 Swing 知识的话),但它非常有限,不适合通用浏览器.
Embedding a browser is not so easy. JEditorPane has some HTML ability (if I remember my limited Swing-knowledge correctly), but it's very limited and not suiteable for a general-purpose browser.
这篇关于你如何在 Java 中打开网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:你如何在 Java 中打开网页?
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
