aspose file tools*
The moose likes Beginning Java and the fly likes How to display one image per day from an array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to display one image per day from an array?" Watch "How to display one image per day from an array?" New topic
Author

How to display one image per day from an array?

Jessica Patrick
Greenhorn

Joined: May 17, 2007
Posts: 4
Hai..

I need to display one image per day from an array depending upon the day in jsp/servlet.

Intially i am having 5 images in an array.

Then i want to display

sunday --- 1st image
monday--- 2nd image
tuesday -- 3rd image
wednesday--4th image
thursday -- 5th image
friday -- 1st image
Saturday-- 2nd image

number of images is dynamically changing.

if the array has one image.. daily that one image should display.
if the array has two image, then 1st day--- 1st image. 2nd day--- 2nd image, 3rd day--- again 1st image.

Can any one please tell me the logic to do this? waiting for your reply.

Thank you...
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Hi,
You must be using a timer task

Regards,
Srikkanth.M
Jessica Patrick
Greenhorn

Joined: May 17, 2007
Posts: 4
Timer task means?
Can you please explain in detail?
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Where exactly are you stuck? Is it the displaying image part or the scheduling part?
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Hi,
You can make use of the Timer class and TimerTask available in J2SE to schedule an event.
You create a task that iterates over the collection of the images and picks one image object.

Refer Timer API


Regards,
Srikkanth.M
Jessica Patrick
Greenhorn

Joined: May 17, 2007
Posts: 4
Here is the code. array length is number of records available in the database. that is retrived in a query.

Calendar cal = Calendar.getInstance();
int dayofweek = cal.get(cal.DAY_OF_WEEK);

if(arraylength==2)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=1;
else if(dayofweek==4)
imagenumber=2;
else if(dayofweek==5)
imagenumber=1;
else if(dayofweek==6)
imagenumber=2;
else if(dayofweek==7)
imagenumber=1;
}
else if(arraylength==3)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=1;
else if(dayofweek==5)
imagenumber=2;
else if(dayofweek==6)
imagenumber=3;
else if(dayofweek==7)
imagenumber=1;
}
else if(arraylength==4)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=4;
else if(dayofweek==5)
imagenumber=1;
else if(dayofweek==6)
imagenumber=2;
else if(dayofweek==7)
imagenumber=3;
}
else if(arraylength==5)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=4;
else if(dayofweek==5)
imagenumber=5;
else if(dayofweek==6)
imagenumber=1;
else if(dayofweek==7)
imagenumber=2;
}
else if(arraylength==6)
{
if(dayofweek==1)
imagenumber=1;
else if(dayofweek==2)
imagenumber=2;
else if(dayofweek==3)
imagenumber=3;
else if(dayofweek==4)
imagenumber=4;
else if(dayofweek==5)
imagenumber=5;
else if(dayofweek==6)
imagenumber=6;
else if(dayofweek==7)
imagenumber=1;
}
else if(arraylength==7)
imagenumber = dayofweek;
else
imagenumber=arraylength;


I am manually checking array length and assigning the image. I need some dynamic calculation for assigning the image. Also this code works only upto 7 images. I need to display even the array length is 25, 50 etc...

Kindly check it out and give me a solution.
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi

Try reading up on the modulo (%) operator. I guess it should be quite helpful.
[ May 17, 2007: Message edited by: Anupam Sinha ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"Jessica",
Welcome to JavaRanch!

We're pleased to have you here with us in the JSP forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

This has nothing to do with a Timer. It's just a simple algorightms question regarding dealing with modulus. It really has nothing to do with JSP either so it's been moved to a general Java forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Ah... I forgot Date and Time API's
Jessica Patrick
Greenhorn

Joined: May 17, 2007
Posts: 4
Hai..

I used the Calendar instance to get the day of the week.

But my question is how can i get the image sequence dynamically.
i need the calculation part alone.

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display one image per day from an array?