本文介绍了你如何用Java打开网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在GUI的JPanel中打开网页?

Is there a simple way to open a web page within a GUI's JPanel?

如果没有,您如何使用计算机的默认Web浏览器打开网页?

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.

推荐答案

使用默认Web浏览器打开网页很简单:

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打开网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 05:48