random web pages loader

Discussion in 'Java' started by SimonP, May 26, 2004.

  1. SimonP

    SimonP Guest

    does any one here know how i could implement a java program to
    automaticaly load random or listed web pages. I thought it would be
    cool to have my laptop displaying a load of pages automatically.

    Simon
    SimonP, May 26, 2004
    #1
    1. Advertising

  2. SimonP

    Roedy Green Guest

    On 26 May 2004 15:09:46 -0700, (SimonP) wrote or
    quoted :

    >does any one here know how i could implement a java program to
    >automaticaly load random or listed web pages. I thought it would be
    >cool to have my laptop displaying a load of pages automatically.


    I do it with a java macro that compose web pages statically.
    here is the code.

    package com.mindprod.htmlmacros;
    import java.io.File;
    import java.util.Random;

    public class RandomLink implements Macro
    {
    /**
    * Generates a link to a randomly chose url,
    * which could be as small as a single letter or even "".
    * invoked with:
    * <!-- macro RandomLink this.html http://mindprod.com/that.html
    .../else.html -->
    *
    * @param parms takes variable number of parms, reprsenting
    possible choice strings to generate.
    * @param fileBeingProcessed
    * @return one of the choices.
    */
    public String expand ( String[] parms, File fileBeingProcessed,
    boolean quiet )
    {
    if ( ! quiet )
    {
    System.out.print( "R" );
    }
    if ( parms.length == 0 )
    {
    throw new IllegalArgumentException ( "RandomLink needs list
    of choices." );
    }
    return expand( parms );

    }

    /**
    * expand RandomLink macro guts
    *
    * @param choices array of possible choices to choose from
    * @return on of the choice strings, randomly chosen
    */
    public String expand ( String[] choices )
    {
    Random wheel = new Random( );
    int pick = wheel.nextInt( choices.length );
    return "<a href=\"" +choices[ pick ] + "\">";
    }

    }


    If want an applet that loads a random page, see
    http://mindprod.com/jgloss/applet.html#LOADING

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, May 26, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    5
    Views:
    1,001
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  2. Karsten Wutzke
    Replies:
    0
    Views:
    386
    Karsten Wutzke
    Jun 29, 2007
  3. globalrev
    Replies:
    4
    Views:
    753
    Gabriel Genellina
    Apr 20, 2008
  4. Nathan Sokalski
    Replies:
    4
    Views:
    280
    Nathan Sokalski
    Dec 21, 2006
  5. VK
    Replies:
    15
    Views:
    1,152
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page