web blazonry web development scripts and tutorials Get best price on Apple iPhone 11
   PHP       Name Generators       Perl       CSS       Javascript       Java       MySql       How Tos       Resources   

Java Home

  iCal Calendar
  Mouse Over w/ Sounds
  Random Image (Motate)
  iNews Applet
  Typewriter Applet
  Text Scroll Applet

  MKJava overview

  Split Fn
  Get Quoted Str Fn

Bookmark and Share

Java Applet: Display Random Image (Motate Applet)

This simple applet randomly displays one of four images when the page is loaded. Each image has a link defined for it. It could serve up ads, for example.

One of the nice things about how this applet is built is that you don't have to re-build it to change the links or the images. Links and images are all defined in HTML on this page.

You could display more or fewer than the 4 images in the demo. Four is what I picked for the demo.

At work we had a CGI script which performed this action, so wrote it in Java. It probably could be easily done in JavaScript, too.

Because of the ad serving application, the demo below displays images from various websites I have worked on and links to the site.

Java Applet Not Shown.
Your browser is not enabled to display Java Applets.

This is just an example, Shift+Reload to see image change.

Because I am the one using this, I did not plan for any errors when entering the parameters. I couple of trys and catches should be used to insure the links and images are actually there.

Also, a double buffering technique could be used to display the image completely, instead of having the image show as it is loaded. Because it only loads one image, I thought this was not necessary.

Get the Source Code  (motate.java.txt)

Here is the HTML part:

<applet code="Motate.class" codebase="classes/" width="336" height="138">
<param name="image1" value="quote1.gif">
<param name="url1" value="http://www.amusing.com/index.php">
<param name="image2" value="quote2.gif">
<param name="url2" value="http://www.crochetkitty.com/index.php">
<param name="image3" value="quote3.gif">
<param name="url3" value="http://www.seatmate.com/index.php">
<param name="image4" value="quote4.gif">
<param name="url4" value="http://www.amusing.com/admiral/index.php">
<param name="n" value="4">
<p><hr><br /><b>Java Applet Not Shown.<br />Your browser is not enabled to display Java Applets.</b><br /><hr></p>



Newest Pages
Test Google Ads Ver. 2
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Most Popular Pages
Baby Name Generator
U.S. Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL
Intro to Web Databases (PHP, MySQL)

Least Popular Pages
iNews Applet (Java)
Java Resources
Site Monitor (Perl)
PHP Resources

  privacy policy     ||     © 1997-2016. astonishinc.com   All Rights Reserved.