Sir,

i m developing a new web browser as my project in java.I have done the initial coding but when i run google homepage on my simple web browser,it shows me some html code online.how to get rid of this code?.i have also attach the view of this problem,plz look at it.

Attachments problem.png 36.06 KB

.how to get rid of this code?

The font of your image is too small, can you copy and paste here what you want us to see?

How can we recommend a change to your code if you don't show it?
Obviously your parser and formatter is not working properly.

Edited 5 Years Ago by NormR1: n/a

following is my code

package javabrowser;

/**
 *
 * @author Administrator
 */
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;
/**
 *
 * @author Administrator
 */
public class JavaBrowser extends JFrame 
 {
    
private JTextField takeURL;
JButton start;
public JEditorPane browserData;
JScrollPane Scroll;
JPanel p,p2;
URL getData;
JFrame frame;

    /**
     * @param args the command line arguments
     */

    public JavaBrowser()
            {
                try
                {
                setTitle("Java Browser");
                   
                setSize(800,600);
                setVisible(true);
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                
               Container pane=getContentPane();
               pane.setLayout(null);

        
               takeURL =new JTextField();
                start=new JButton("Start");
                
                browserData=new JEditorPane();
                browserData.setContentType("text/html");
                browserData.setEditable(false);
                browserData.addHyperlinkListener(new LinkActivator() );

                Scroll=new JScrollPane(browserData);
                Scroll.setPreferredSize(new Dimension(503,503));
                //Scroll.setAutoscrolls(true);
                Scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                p=new JPanel();
                p.add(Scroll); 

                takeURL.setLocation(10,10);
                takeURL.setSize(500, 20) ;
                start.setLocation(510,10 );
                start.setSize(80, 20) ;
              start.addActionListener(new ActionListener(){
                  public void actionPerformed(ActionEvent e) 
                  
                  {
                      
                     String string_of_url=new String(takeURL.getText()); 
                     getData(string_of_url);
                     
                  }} );
                browserData.setLocation(0,0);
                browserData.setSize(500, 500) ;
                p.setLocation(10,40);
                p.setSize(508,508) ;
                pane.add(takeURL);
                pane.add(start); 
                pane.add(p);
                }
                catch(Exception e)
                {
                    
                }
               
                
            }
    class LinkActivator implements HyperlinkListener {
    public void hyperlinkUpdate(HyperlinkEvent he) {
      HyperlinkEvent.EventType type = he.getEventType();
      if (type == HyperlinkEvent.EventType.ACTIVATED)
          try
          {
              getData(he.getURL().toString());
          }
      catch(Exception ie)
      {
      }
    }
  }
    public void getData(String string_of_url)
    {
        try
        {
             
          URL oracle = new URL(string_of_url+ "/");
        browserData.setPage(oracle);
        
        
        }
        catch(Exception e)
        {
        }
    }
   

    public static void main(String[] args) {
        // TODO code application logic here
       
        JavaBrowser jb=new JavaBrowser();
     
        
    }
    
}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

java can't read Javascripts. The code that is showing you the program is a javascript.

how to get rid of this code

Read the text of the page and remove the parts that your display engine doesn't know how to format before giving it the text.

Please edit your code and wrap it in code tags. See [code] icon above input box.

the best way to do a web browser is using another language instead of Java. It would be a whole project to execute javascripts.

using another language instead of Java

@teo 236 Can you explain what the problem is with doing it in Java?

Edited 5 Years Ago by NormR1: n/a

it will be very confusing trying to execute javascripts in java. maybe there is a better language for this kind of projects. If hamzamuradkhanh wants to execute javascripts with java, it's possible but would probably be very slow execution. I researched and found this page http://www.mozilla.org/rhino/ if you are interested.

This article has been dead for over six months. Start a new discussion instead.