使用java创建Web浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3064732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using java to create a web browser
提问by prasad
Is it possible to use Java to build a web browser like Internet Explorer that will open all the web pages and display all the contents?
是否可以使用 Java 构建一个像 Internet Explorer 这样的 Web 浏览器,它可以打开所有网页并显示所有内容?
采纳答案by OscarRyz
Yes, it is possible. JWebPane is a work in progress migration of Webkit. It is supposed to be included in JDK7 but I wouldn't hold my breath.
对的,这是可能的。JWebPane 是 Webkit 的一个正在进行的迁移工作。它应该包含在 JDK7 中,但我不会屏住呼吸。
JWebPane browser = new JWebPane();
new JFrame("Browser").add(browser);
browser.load(someURL);
回答by VoteyDisciple
The only valid answer to that question is:
该问题的唯一有效答案是:
Yes, it's possible to use Java to build a web browser.
是的,可以使用 Java 构建 Web 浏览器。
However, a web browser is an exceptionally complex piece of software. Even Google, when building its Google Chrome browser, used existing technology to do it, rather than inventing their own browser from scratch.
但是,Web 浏览器是一个异常复杂的软件。甚至 Google 在构建 Google Chrome 浏览器时,也是使用现有技术来实现的,而不是从头开始发明自己的浏览器。
If your goal is anything other than building and marketing your own browser, you may want to reconsider what exactlyyou want to accomplish, in order to find a more direct approach.
如果您的目标不是构建和营销您自己的浏览器,您可能需要重新考虑您到底想要完成什么,以便找到更直接的方法。
回答by luvieere
I advise you to take a look at the Lobo Browserproject, an open-source java-written web browser. Take a look at the source and see how they did it.
我建议您查看Lobo Browser项目,这是一个开源的 Java 编写的 Web 浏览器。看看源,看看他们是如何做到的。
回答by James Kingsbery
Yes, it's possible, and here's what you would need to start looking at.
是的,这是可能的,这是您需要开始查看的内容。
First, search for an HTML renderer in Java. An example would be JWebEngine. You can start by manually downloading HTML pages and verifying that you can view them.
首先,在 Java 中搜索 HTML 渲染器。一个例子是 JWebEngine。您可以先手动下载 HTML 页面并验证您是否可以查看它们。
Second, you need to handle the networking piece. Read a tutorial on sockets, or use an HTTP Client such as the Apache HTTPClient project.
其次,您需要处理网络部分。阅读有关套接字的教程,或使用 HTTP 客户端,例如 Apache HTTPClient 项目。
Edit: Just to add one more thought, you should be honest with yourself about why you would work on this project. If it's to rebuild IE, FF, that is unrealistic. However, what you might get out of it is learning what the major issues are with browser development, and that may be worthwhile.
编辑:再补充一点,你应该对自己诚实地说明为什么要从事这个项目。如果是重建IE、FF,那是不现实的。但是,您可能从中得到的是了解浏览器开发的主要问题是什么,这可能是值得的。
回答by Adamski
Take a look at the JEditorPane
class. It can be used to render HTML pages and could form the basis of a simple browser.
看看JEditorPane
班级。它可用于呈现 HTML 页面,并可构成简单浏览器的基础。
回答by gimenete
The hardest thing will be the rendering component. Java7 will include JWebPane, that internally uses WebKit. Here you can find some screenshots.
最难的是渲染组件。Java7 将包括内部使用 WebKit 的 JWebPane。在这里您可以找到一些屏幕截图。
回答by Bill the Lizard
Yes. One of the projects in Java After Hoursshows you how to build a simple web browser. It's not nearly as full-featured as IE or Firefox of course (it's only one chapter in the book), but it will show you how to get started.
是的。Java After Hours中的一个项目向您展示了如何构建一个简单的 Web 浏览器。它当然不像 IE 或 Firefox 那样功能齐全(这只是本书的一章),但它会向您展示如何开始。
回答by Dhiral Pandya
I develop thisbrowser for my college project may be thishelpful for you
My Button is open source java web browser.
My Button 是开源的 Java 网络浏览器。
Develop for school and college projects and learning purpose. Download source code extract .zip file and copy “mybutton” folder from “parser\mybutton” to C:\
为学校和大学项目和学习目的而开发。下载源代码解压 .zip 文件并将“mybutton”文件夹从“parser\mybutton”复制到 C:\
Import project “omtMyButton” in eclipse. Require Java 6.
在 Eclipse 中导入项目“omtMyButton”。需要 Java 6。
Download .exe and source code : https://sourceforge.net/projects/omtmybutton/files/
下载 .exe 和源代码:https: //sourceforge.net/projects/omtmybutton/files/