-
google in web browser
HI
Can anyone help i have created this web browser (code underneath), but i cant get google results up. Does anyone have any sujestions.
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
public class ReadServerFile extends JFrame {
private JTextField enter;
private JEditorPane contents;
public ReadServerFile()
{
super( "Jeff's Browser" );
Container c = getContentPane();
enter = new JTextField( "Enter file URL here" );
enter.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
{
getThePage( e.getActionCommand() );
}
}
);
c.add( enter, BorderLayout.NORTH );
contents = new JEditorPane();
contents.setEditable( false );
contents.addHyperlinkListener(
new HyperlinkListener() {
public void hyperlinkUpdate( HyperlinkEvent e )
{
if ( e.getEventType() ==
HyperlinkEvent.EventType.ACTIVATED )
getThePage( e.getURL().toString() );
}
}
);
c.add( new JScrollPane( contents ),
BorderLayout.CENTER );
setSize( 400, 300 );
show();
}
private void getThePage( String location )
{
setCursor( Cursor.getPredefinedCursor(
Cursor.WAIT_CURSOR ) );
try {
contents.setPage( location );
enter.setText( location );
}
catch ( IOException io ) {
JOptionPane.showMessageDialog( this,
"Error retrieving specified URL",
"Bad URL",
JOptionPane.ERROR_MESSAGE );
}
setCursor( Cursor.getPredefinedCursor(
Cursor.DEFAULT_CURSOR ) );
}
public static void main( String args[] )
{
ReadServerFile app = new ReadServerFile();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
Thanx Jeff
-
To help debug, we need to see what the data was. Add a println("loc=" + location) statement to show the value being looked up. Also your error message could show the bad URL!
Then copy the output from the program and paste it here.
Do you know the format for a valid URL?
protocol hostname portnumber filename reference (without the spaces)