Computers, Java, Programming

Creating a Simple Java Web Browser

Creating a simple web browser in Java is quite simple. Although i teach C++ (i must confess), for ease and speed of programming Java is great for beginners, especially for multi-platform GUI applications. That said, below is code for a simple Java based web browser. You could easily modify this code to browse the web for you autonomously (like a web trawling robot etc. great for advertising, or data mining – or just to create a quick search tool that does the work for you while you go have some lunch). You could also make a custom web browser for a special project – although don’t bother trying to compete against Firefox etc… especially if your only one person, it takes teams of people and many years to reach where we are today.
Just cut, paste, compile and run!
For those new to Java…
e.g.
To compile:

javac WebBrowser.java 

To run:

java WebBrowser

Enjoy

WebBrowser.java

About these ads
Standard

16 thoughts on “Creating a Simple Java Web Browser

  1. himapm says:

    Hi,

    Hope you r doing gud.
    I tried using the above code for web browser.
    However, after running, I get the window where I can enter the url. But nothing seems to come.. I get connection refused error message. Do I have to do some settings change in IE ?

  2. C:\Users\Zeromin0\Desktop\WebBrowser.java:84: ‘try’ without ‘catch’ or ‘finally’
    try
    ^
    C:\Users\Zeromin0\Desktop\WebBrowser.java:88: illegal start of type
    });
    ^
    C:\Users\Zeromin0\Desktop\WebBrowser.java:89: expected
    editable = new JCheckBox();
    ^
    C:\Users\Zeromin0\Desktop\WebBrowser.java:90: expected
    editable.addActionListener(new ActionListener()
    ^
    C:\Users\Zeromin0\Desktop\WebBrowser.java:90: illegal start of type
    editable.addActionListener(new ActionListener()
    ^
    C:\Users\Zeromin0\Desktop\WebBrowser.java:92: illegal start of expression
    public void actionPerformed(ActionEvent event)
    ^
    6 errors

  3. Your browser is working great browsing wikipedia. The browsing of your site is working fine too; the google page is shown but no queries are transacted.

    And this browser, which does its work 100 times better than lynx or the emacs-browser-plugin, needs only 110 lines of code – instead of hundreds of functions in lynx and instead of more than a dozend LISP-Files in the emacs-browser-plugin.

    It compile without any problem in IntelliJ-IDE (IDEA-13.0.2).

    That is really, really a very sophisticated Java-Code.

    The core of the browser seems to be this three lines:

    urlStack.push(event.getURL().toString());
    url.setText(event.getURL().toString());
    editorPane.setPage(event.getURL());

    Thanks a lot…. you are a genius

  4. Pingback: Creating a Simple Java Web Browser with less than 110 lines of code | sophismos

  5. Hello,I am start my first core java project.
    I can think to make a web browser.
    But i have trouble for its packages to import.
    And many other code problem.
    Please,Help me.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s