Need a String loop or something

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chellemybelle
    New Member
    • Nov 2007
    • 4

    #1

    Need a String loop or something

    Hello,

    I basically have made a little cheezy slideshow and would like to add captions to each pic as it loops through. I've tried everything I can think of. I'm assuming I might need to use an array for the string but not sure. Here is my code so far. I've included the strings I'm trying to add as variables for right now. Please have look, and I would greatly appreciate any suggestions you may have on including a string loop synced with my pics. Please and thank you:)
    public class Tour extends JApplet implements Runnable
    {
    //*************** *************** **********insta nce variables
    private Image[] loop;
    private int numImages = 4;
    private int currentImage = 0;
    private int numStrings = 4;
    private int currentString = 0;
    private String caption0 = "Our Java Jive Mall Lobby";
    private String caption1 = "Enjoy Family Dining at Michelle's Little Italy";
    private String caption2 = "Grab lunch at Greg Bunch's Mexican Lunches";
    private String caption3 = "Have Some Fun at our Java Jive Arcade";


    private Thread animate = null;
    private MediaTracker tracker = null;
    /*************** ************oth er instance variables*/
    Image loadingImage;
    //*************** *************** *************** **init method
    public void init()
    {
    loadingImage = getImage(getDoc umentBase(), "LoadingClock.g if");
    tracker = new MediaTracker(th is);

    loop = new Image[numImages];

    for(int x = 0;x<loop.length ;x++)
    {
    loop[x] = getImage(getDoc umentBase(),"To ur" + x + ".jpg");
    tracker.addImag e(loop[x],0);
    }
    animate = new Thread(this);
    animate.start() ;

    } //end of init()

    //*************** *************** *************** ***run method
    public void run()
    {
    try {
    tracker.waitFor All();

    for(;;)
    {
    currentImage = (currentImage + 1) % numImages;
    repaint();

    Thread.sleep(20 00);
    }
    }catch(Interrup tedException e) {
    showStatus(e.to String());
    }

    }//end of run()
    //*************** *************** *************** *paint method

    public void paint(Graphics g)
    {

    if(tracker.chec kAll())
    {
    g.drawImage(loo p[currentImage],0,0,500,400,th is);
    }
    else
    {
    g.drawImage(loa dingImage,150,1 50,150,150,this );
    g.drawString("T our loading...Pleas e wait...",80,65) ;
    }
    } //end of paint()
    } //end of Tour class
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    It seems you have already done all the hard work -- reading in the images and writing an animation loop to cycle through the image array. What if you put the captions in an array as well?

    Comment

    • chellemybelle
      New Member
      • Nov 2007
      • 4

      #3
      Thanks for the reply. Yeah I tried to do that already. I'm guessing thats what needs to be done but I can't quite work it out. I looked through Sun java's docs and can't find a good example either. I can intialize the String array, but can someone show what else to do to get the strings synced with the pics?

      Comment

      • Laharl
        Recognized Expert Contributor
        • Sep 2007
        • 849

        #4
        Could you use a map? Otherwise, I think you'd sync them by ensuring that a picture in its array is at the same index as its caption is in the String[].

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Originally posted by Laharl
          Could you use a map? Otherwise, I think you'd sync them by ensuring that a picture in its array is at the same index as its caption is in the String[].
          Indeed. OP, are you familiar with the syntax for initializing an array of Strings?
          [CODE=java]
          String[] captions = {
          "caption 0",
          "caption 1",
          ...
          "captionN"
          };
          [/CODE]
          You're almost done, at this point.

          Comment

          Working...