13 Replies - 3330 Views - Last Post: 05 December 2011 - 11:03 AM

#1 harshakirans   User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 124
  • Joined: 26-April 06

basic browser

Posted 25 February 2007 - 08:16 PM

Description: simple basic browser.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;

public class WebBrowser
{
     public static void main(String [] args)
     {
          JFrame frame = new EditorPaneFrame();
          frame.show();
     }
}
class EditorPaneFrame extends JFrame
{

     private JTextField url;
     private JCheckBox editable;
     private JButton loadButton;
     private JButton backButton;
     private JEditorPane editorPane;
     private Stack urlStack = new Stack();


     public EditorPaneFrame()
     {
          setTitle("Java Web Browser");
          setSize(600,400);
          addWindowListener(new WindowAdapter()
          {
               public void windowClosing(WindowEvent e)
               {
                    System.exit(0);
               }
          } );

          // set up text field and load button for typing in URL

          url = new JTextField(30);

          loadButton = new JButton("Load");
          loadButton.addActionListener(new ActionListener()
          {
               public void actionPerformed(ActionEvent event)
               {
                    try
                    {
                         // remember URL for back button
                         urlStack.push(url.getText());
                         editorPane.setPage(url.getText());
                    }
                    catch(Exception e)
                    {
                         editorPane.setText("Error: " +e);
                    }
               }
          });

          // set up back button and button action

          backButton = new JButton("Back");
          backButton.addActionListener(new ActionListener()
          {
               public void actionPerformed(ActionEvent event)
               {
                    if(urlStack.size()<=1) return;
                    try
                    {
                         urlStack.pop();
                         String urlString = (String)urlStack.peek();
                         url.setText(urlString);
                         editorPane.setPage(urlString);
                    }
                    catch(IOException e)
                    {
                         editorPane.setText("Error : " +e);
                    }
               }
          });

          editorPane = new JEditorPane();
          editorPane.setEditable(false);
          editorPane.addHyperlinkListener(new HyperlinkListener()
          {
               public void hyperlinkUpdate(HyperlinkEvent event)
               {
                    if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                    {
                         try
                         {
                              urlStack.push(event.getURL().toString());
                              url.setText(event.getURL().toString());

                              editorPane.setPage(event.getURL());
                         }
                         catch(IOException e)
                         {
                              editorPane.setText("Error: " + e);
                         }
                    }
               }
          });

          editable = new JCheckBox();
          editable.addActionListener(new ActionListener()
          {
               public void actionPerformed(ActionEvent event)
               {
                    editorPane.setEditable(editable.isSelected());
               }
          });

          Container contentPane = getContentPane();
          contentPane.add(new JScrollPane(editorPane), "Center");

          JPanel panel = new JPanel();
          panel.add(new JLabel("URL"));
          panel.add(url);
          panel.add(loadButton);
          panel.add(backButton);
          panel.add(new JLabel("Editable"));
          panel.add(editable);

          contentPane.add(panel,"South");
     }

}



Is This A Good Question/Topic? 0
  • +

Replies To: basic browser

#2 purandar   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-August 08

Re: basic browser

Posted 26 August 2008 - 07:40 AM

hey... good post.. i compiled it n it showed no error .. but.how do i run it..?
Was This Post Helpful? 0
  • +
  • -

#3 purandar   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-August 08

Re: basic browser

Posted 02 September 2008 - 06:36 AM

its not connecting da...jus rep me [email protected]
Was This Post Helpful? 0
  • +
  • -

#4 harshakirans   User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 124
  • Joined: 26-April 06

Re: basic browser

Posted 03 September 2008 - 09:18 PM

Dude check if you have any automatic proxy configurations settings in your connection, And the URL encoding part is not included in the code..Well i think that should be the problem
Was This Post Helpful? 0
  • +
  • -

#5 jack_lorren   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-March 09

Re: basic browser

Posted 06 March 2009 - 06:41 AM

i think it not automatic,you must write "http://"
Was This Post Helpful? 0
  • +
  • -

#6 nafees88   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 05-June 09

Re: basic browser

Posted 05 June 2009 - 09:48 PM

www.chatpk.tk
Was This Post Helpful? 0
  • +
  • -

#7 syfran   User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: basic browser

Posted 12 July 2009 - 09:49 AM

Only three stars for this? That's what the snippet that added two numbers together got. Great submission, worked perfectly for me. 5/5
Was This Post Helpful? 0
  • +
  • -

#8 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: basic browser

Posted 17 July 2009 - 06:11 PM

Jolly good show
Was This Post Helpful? 0
  • +
  • -

#9 sh1n3   User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 164
  • Joined: 22-April 10

Re: basic browser

Posted 18 June 2010 - 08:50 PM

Why is showing as deprecated for me, even after i changed it frame.setVisible(true);
Was This Post Helpful? 0
  • +
  • -

#10 pankaj kashyap   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 21-June 10

Re: basic browser

Posted 21 June 2010 - 05:14 AM

its fine& simple coding in java.how we code browser like explorer in html,javascript & bin programing
Was This Post Helpful? 0
  • +
  • -

#11 rajz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 10-October 10

Re: basic browser

Posted 10 October 2010 - 09:09 AM

hi i dn't able to search on google via ur browser.. help me at my java browser project... how do i code parser for javascript php xml like formats how do i handle cookies and privacy data.. plz do some help.. thanks in advance
Was This Post Helpful? 0
  • +
  • -

#12 shri27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 08-February 11

Re: basic browser

Posted 08 February 2011 - 01:17 AM

cool,it is working
Was This Post Helpful? 0
  • +
  • -

#13 khan_roktim   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-June 11

Re: basic browser

Posted 15 June 2011 - 06:44 AM

hi i dn't able to search on google via ur browser.. help me at my java browser project... how do i code parser for javascript php xml like formats how do i handle cookies and privacy data.. plz do some help.. thanks in advance....nd plz do rply as soon as possible
Was This Post Helpful? 0
  • +
  • -

#14 billy81   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 24-February 09

Re: basic browser

Posted 05 December 2011 - 11:03 AM

This is brilliant!! i've been trying to put a browser together for a couple of weeks.This helps a lot in figuring out how it works.I copied it and it worked first time...Great job! Thanks for taking the time to do it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1