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);
}