I have written a browser in java but it is only able to display saved web pages on my computer or html files created by me.
It is not able to display a page when i type any URL in the address bar.
Please help me
Here is the code

import javax.swing.JEditorPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;


public class BuildBrowseGUI extends JFrame
{
    private JTextField enterField;
    private JEditorPane contentsArea;
    
     public  void getThePage(String location)
                        {
                            try
                            {
                                contentsArea.setPage(location);
                                enterField.setText(location);
                            }
                            catch(IOException e)
                            {
                                JOptionPane.showMessageDialog(this,"Error retrieving requested URL",
                                        "Error Loading",JOptionPane.ERROR_MESSAGE);
                            }
                        }
    
    public BuildBrowseGUI()
    {
        super("MoniWeb Navigator (Prototype version) by PIE EDWARD");
        setLayout(new BorderLayout());
        enterField=new JTextField("Enter address here");
        enterField.addActionListener(
                new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                getThePage(event.getActionCommand());
            }
        }
                );
                add(enterField,BorderLayout.NORTH);
                contentsArea=new JEditorPane();
                contentsArea.setEditable(false);
                contentsArea.addHyperlinkListener(
                        new HyperlinkListener()
                {
                    public void hyperlinkUpdate(HyperlinkEvent event)
                    {
                        if(event.getEventType()==HyperlinkEvent.EventType.ACTIVATED)
                        {
                            getThePage(event.getURL().toString());
                        }
                    }
                }
                        );
                        add(new JScrollPane(contentsArea),BorderLayout.CENTER);
                        
                       
    }

... And how do you propose someone help you, when you have not posted a clear question nor any code?

I don't know what your "getThePage()" method looks like. I'm assuming you're trying to listen for the ENTER key? Add a KeyListener to the text field. To set the page, look at the following method in the Java docs: JEditorPane.setPage(URL page)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.