Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2008, 05:30 AM
Member
 
Join Date: Oct 2008
Posts: 30
Rep Power: 0
Urgle is on a distinguished road
Default Applet Slideshow in web browser
I wrote an applet to be run in a browser to display images but im not sure were to put my jpgs so it can find the pictures. Heres my code and my html:

Code:
package Final;

import java.util.*;
import java.applet.*;
import java.awt.*;

public class FFinal extends Applet implements Runnable {
  MediaTracker tracker;
  int tracked;
  int frame_rate = 5;
  int current_img = 0;
  Thread motor;
  static final int MAXIMAGES = 10;
  Image img[] = new Image[MAXIMAGES];
  String name[] = new String[MAXIMAGES];
public void init() {
    		tracker = new MediaTracker(this);
   		 StringTokenizer st = new StringTokenizer(getParameter("img"), "+");
    		while(st.hasMoreTokens() && tracked <= MAXIMAGES) {
      			name[tracked] = st.nextToken( );
      			img[tracked] = getImage(getDocumentBase(), name[tracked] + ".jpeg");
      			tracker.addImage(img[tracked], tracked);
      			tracked++;
    		 }
  	}

  	public void paint(Graphics g) {
    		String loaded = "";
    		int donecount = 0;
    		for(int i=0; i<tracked; i++) {
      			if (tracker.checkID(i, true)) {
       				donecount++;
       				 loaded += name[i] + " ";
      			}
    		}
    		Dimension d = size();
    		int w = d.width;
    		int h = d.height;
    
    		if (donecount == tracked) {
      			frame_rate = 1;
      			Image i = img[current_img++];
      			int iw = i.getWidth(null);
      			int ih = i.getHeight(null);
      			g.drawImage(i, (w - iw)/2, (h - ih)/2, null);
      			if (current_img >= tracked)
        				current_img = 0;
    			} 
    		else {	int x = w * donecount / tracked;
      			g.setColor(Color.black);
      			g.fillRect(0, h/3, x, 16);
      			g.setColor(Color.white);
      			g.fillRect(x, h/3, w-x, 16);
      			g.setColor(Color.black);
      			g.drawString(loaded, 10, h/2);
    			}
  	}
  	public void start() {
    		motor = new Thread(this);
    		motor.start( );
  	}
  	public void stop() {
    		motor.stop();
  	}
  	public void run() {
    		motor.setPriority(Thread.MIN_PRIORITY);
    		while (true) {
      			repaint();
      			try { Thread.sleep(1000/frame_rate);
      			      } catch (InterruptedException e) { }
    		}
  	}       
}
Code:
<html>

<applet
  codebase = "."
  code     = "Final.FFinal.class"
  name     = "TestApplet"
  width    = "400"
  height   = "300"
  hspace   = "0"
  vspace   = "0"
  align    = "middle"
>
<param name="img"
 value="HW.jpg">

</applet>

</html>
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser Jessie Madman AWT / Swing 20 02-17-2009 02:56 PM
Problem with applet, between appletviewer and browser Goodwine Java Applets 0 11-30-2008 04:09 AM
applet won't run in browser... shwein Java Applets 6 10-17-2008 07:24 PM
how to get url from browser srinivas reddy New To Java 0 02-08-2008 08:46 AM
Applet, To center text and To open I engage in a dialog in an Applet Marcus Java Applets 4 06-08-2007 07:15 AM


All times are GMT +2. The time now is 10:07 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org