开发者

Implementing a lightweight java webbrowser

开发者 https://www.devze.com 2023-02-15 03:48 出处:网络
This is my first question on Stack Overflow , so if it is bad form please excuse and correct me ! As the Title implies I am trying to implement a light-weight web browser in Java , however I am runni

This is my first question on Stack Overflow , so if it is bad form please excuse and correct me !

As the Title implies I am trying to implement a light-weight web browser in Java , however I am running into a problem but before I go into details I will provide a brief description of my implementation :

The program consists of the following classes:

GUI (Extends JFrame implements HyperlinkListener) : The graphical user interface

Engine : Does all the actual work

BlackListPolicy (implements CookiePolicy)

I am using a JEditorPane with its content set to "text/html" to display the webpages Whenever the "GO" button or a link is clicked the Engine gets a URL and then JEditorPane.setPage(URL)

So this brings me 开发者_开发技巧to the first part of my question :

The browser is working , however only simple html pages are being displayed if I go to Google for example If I click a link it works , it remembers my settings (Cookies) but if a press "Google search" button for example nothing happens , no embedded objects (Flash , applets , etc.) are displayed and other pages are not being encoded properly

My theory is either that JEditorPane can't display such objects and is not a good choice for a web browser , or that I Set the wrong content type for it.

As for part two of my question :

As a cookieHandler I am doing the following:

BlackListPolicy blackListPolicy = new BlackListPolicy();

CookieManager cookieManager = new CookieManager(null, blackListPolicy);

Thus I am using the default CookieStore , which to my limited understanding uses an internal implementation to store Cookies (they are not persistent) which is what I want However if someone would go on what I would call "an extreme browsing session" storing an excessive amount of cookies would that cause any performance or memory issues or does the default CookieStore handle such cases?

Before you ask , yes I am a student but this is not a homework assignment or even something that is related to my current programing Courses , this is something that I want to implement because I noticed that the best way to learn programing is to write programs

I only need Abstract answers maybe with a link that would send me towards the right direction , if you would like me to post my code I would gladly do so

~Thanks


Your settings are not wrong on your JEditorPane as it only supports a small subset of HTML. If you want something better you are going to have to build an entire browser yourself which definitely is not a small project.


I know this is an old post, but, have you considered using HTMLUnit?

It's a bit complex but I think it's what you're looking for - a fully java based browser library with full JS support.

http://htmlunit.sourceforge.net/

0

精彩评论

暂无评论...
验证码 换一张
取 消