Results 1 to 2 of 2
  1. #1
    jeff666 is offline Member
    Join Date
    Jul 2008
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    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)
    Last edited by Norm; 07-06-2008 at 08:05 PM.

Similar Threads

  1. Browser
    By Jessie Madman in forum AWT / Swing
    Replies: 20
    Last Post: 02-17-2009, 01:56 PM
  2. Need Help! swt/Browser
    By sealyu in forum SWT / JFace
    Replies: 4
    Last Post: 07-09-2008, 08:16 PM
  3. how to get url from browser
    By srinivas reddy in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 07:46 AM
  4. Google Maps API
    By mew in forum New To Java
    Replies: 0
    Last Post: 12-26-2007, 10:28 AM
  5. Google Singleton Detector 0.7.2
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-26-2007, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •