KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > banner > BannerModule


1 package com.openedit.modules.banner;
2
3 import java.util.Random JavaDoc;
4
5 import com.openedit.WebPageRequest;
6  
7
8 public class BannerModule {
9
10     Random JavaDoc fieldRandom;
11
12     public Random JavaDoc getRandom()
13     {
14         if (fieldRandom == null)
15         {
16             fieldRandom = new Random JavaDoc();
17         }
18         return fieldRandom;
19     }
20
21     public void setRandom(Random JavaDoc inRandom)
22     {
23         fieldRandom = inRandom;
24     }
25
26     public void randomNumber(WebPageRequest inReq ) throws Exception JavaDoc
27     {
28            String JavaDoc toplimit = inReq.getCurrentAction().getChildValue("toplimit");
29            if ( toplimit == null)
30            {
31                toplimit = "3";
32            }
33            int topmost = Integer.parseInt(toplimit);
34            int num = getRandom().nextInt(topmost);
35                  //num is number from 0 to 3
36
num++; //add one to it
37

38            inReq.putPageValue( "bannernumber",String.valueOf( num ) );
39     }
40 }
41
Popular Tags