Re: Creating a Photo Slideshow in GWT

1,193 views
Skip to first unread message
Message has been deleted

Srini Marreddy

unread,
Aug 6, 2008, 12:49:07 PM8/6/08
to Google Web Toolkit
Use GWT Timer class and schedule the URL Change in run method. The
code will be roughly like this.

List imageURLs = new ArrayList();
// Add image urls to the above list

Timer timer = new Timer() {
int index = 0;
public void run() {
/*Set image URL to the image object created else where in your code*/
image.setUrl((String)imageURLs.get(index);
index++;
if( ( imageURLs .size() -1) == index){
index = 0;
}
}
};
timer.scheduleRepeating(1000) ;

-Srini

timer.
On Aug 6, 9:37 am, Gaunt Face <matt.t.ga...@googlemail.com> wrote:
> Hey everyone
>
> I hope that this isn't a stupid question, I'm new to new GWT been
> playing around with it for couple of days attempting to re-vamp an
> existing website.
>
> Im trying to create a very simple photo slideshow that loops around 3
> images and displaying them.
>
> While I understand how to get the image to display and also how to
> make it change from a user click, I can't get my head around how to
> make my application do this on its own.
>
> Can anyone just point me in the right direction?
>
> Many Thanks
> Gaunt
Message has been deleted

Joseph Lust

unread,
Jul 10, 2012, 6:12:38 PM7/10/12
to google-we...@googlegroups.com, Google Web Toolkit
Here is a working example for you. Your variable names were not consistent and you also did not appear to attach any of the objects you made to the DOM.

See the "imgContainer" div I referred to in the example. This is just a dive in the YourModule.html file (for your given module). Images will be rotated in that div.


	/** SAMPLE **/
	final List<String> imageURLs = new ArrayList<String>();
	// Add image urls to the above list
	imageURLs.add("images/image1.png");
	imageURLs.add("images/image2.png");
	imageURLs.add("images/image3.png");

	// make panels to hold images
	final Image baseImg = new Image(imageURLs.get(0));
	VerticalPanel imgPanel = new VerticalPanel();
	imgPanel.add(baseImg);
	// attach
	RootPanel.get("imgContainer").add(imgPanel);

	// create timer
	Timer timer = new Timer() {
		int index;
		
		@Override
		public void run() {
			// rotate
			index = (index+1<imageURLs.size()) ? index+1 : 0;
			baseImg.setUrl( imageURLs.get(index) );
		}
	};
	// schedule rotation of image
	timer.scheduleRepeating(1000); //1s

Sincerely,
Joseph
Reply all
Reply to author
Forward
0 new messages