473,379 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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
{
//****************************************instance 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;
/***************************other instance variables*/
Image loadingImage;
//***********************************************ini t method
public void init()
{
loadingImage = getImage(getDocumentBase(), "LoadingClock.gif");
tracker = new MediaTracker(this);

loop = new Image[numImages];

for(int x = 0;x<loop.length;x++)
{
loop[x] = getImage(getDocumentBase(),"Tour" + x + ".jpg");
tracker.addImage(loop[x],0);
}
animate = new Thread(this);
animate.start();

} //end of init()

//************************************************ru n method
public void run()
{
try {
tracker.waitForAll();

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

Thread.sleep(2000);
}
}catch(InterruptedException e) {
showStatus(e.toString());
}

}//end of run()
//**********************************************pain t method

public void paint(Graphics g)
{

if(tracker.checkAll())
{
g.drawImage(loop[currentImage],0,0,500,400,this);
}
else
{
g.drawImage(loadingImage,150,150,150,150,this);
g.drawString("Tour loading...Please wait...",80,65);
}
} //end of paint()
} //end of Tour class
Dec 8 '07 #1
4 1607
BigDaddyLH
1,216 Expert 1GB
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?
Dec 8 '07 #2
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?
Dec 9 '07 #3
Laharl
849 Expert 512MB
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[].
Dec 9 '07 #4
BigDaddyLH
1,216 Expert 1GB
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?
Expand|Select|Wrap|Line Numbers
  1. String[] captions = {
  2.     "caption 0",
  3.     "caption 1",
  4.     ...
  5.     "captionN"
  6. };
  7.  
You're almost done, at this point.
Dec 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error...
6
by: Martijn van Oosterhout | last post by:
I've had some fun in the past where I've had to grant a lot of tables and other similar system commands. Unfortunatly, you can't use queries to fill in fields for you. Anyway, I've implemented a...
2
by: Wayne Wengert | last post by:
This is my first attempt to re-write an old VB6 application that exported a CSV file to a .NET application that exports an XML file with the equivelent data. I have limited understanding of OO...
2
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist...
16
by: C++ Hell | last post by:
Hey everyone just designing a quiz for school and managed to write the code for the questions and answers thou i have to add scores and at the end an overall score does anyone have any idea what to...
31
by: Martin Jørgensen | last post by:
Hi, I've had a introductory C++ course in the spring and haven't programmed in C++ for a couple of months now (but I have been programmed in C since january). So I decided to do my conversion...
46
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My...
8
by: mvdave | last post by:
Hello all & I hope I'm posting in the right place.. I need to load a temporary table with a range of sequential dates, passing it a beginning and an end date from a criteria form. I have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.