Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-15-2008, 07:24 PM
f_the_cook's Avatar
Member
 
Join Date: May 2008
Posts: 21
Rep Power: 0
f_the_cook is on a distinguished road
Default christmas class
hello yet again i need some help with my code if you would. what im trying to do is make the 12 days of Christmas in an applet while playing the music. the problem im having is i need it when i run it to have it say on the first day etc. and then make a new line and start with on the second day. ill show you the code i have so far.

Code:
import java.awt.*;
import javax.swing.*;
public class Christmas 
{

    public static String ChristmasRecursion(int day,int tempDay,int lastDay) 
    {
    	int giftDay=tempDay;
    	int secondDay=day;
    	String result="";
    	String[] dayLyrics = new String[]    	
    		{"first","second","third","fourth","fifth","sixth","seventh","eigth","nineth","tenth","eleventh","twelfth"};
    		
    		
    		String [] gifts=new String[]
    		{"","a partirige in a pear tree!\n\n","turtle doves\n", "french hens\n" , "calling birds\n", "golden rings\n" ,"geese a-laying\n","swans a-swimming\n"
    			,"maids a-milking\n","ladies dancing\n","lords a-leaping\n","pipers piping\n","drummers drumming\n" };
    		
    		
    	String myTrue="my true love gave to me\n ";
    	
    	if ((day==11)|| (day==lastDay))
    	{
    		result+=( "On the "+dayLyrics[day]+" day of christmas "+myTrue+ "\n");
    			//gifts[day]);
    		
    		while (tempDay!=0)
    		{
    			if ((tempDay==1)&&(secondDay!=0))
    			{
    				result+="And ";
    			}
    			if (day!=0)
    			{
    				result+=((day+1)+ " ");
    			}
    			result+=gifts[tempDay]+"\n";
    			tempDay--;
    			day--;
    			
    		}
    		tempDay=giftDay;
    		day=secondDay;
    		result+="\n\n\n\n\n\n\n";
    	}
    	else
    	{
    		result+=( "\n\n\nOn the "+dayLyrics[day]+" day of christmas "+myTrue+ "\n");
    		
    		while (tempDay!=0)
    		{
    			if ((tempDay==1)&&(secondDay!=0))
    			{
    				result+="And ";
    			}
    			if(day!=0)
    			{
    				result+=((day+1)+" ");
    			}
    			result+=gifts[tempDay]+"\n";
    			tempDay--;
    			day--;
    		}
    		tempDay=giftDay;
    		day=secondDay;
    		
    		
    		result+=ChristmasRecursion((day+1),(tempDay+1),lastDay);
    	}	
    			
    	return result;	
    	
    }
    
    
    
}

thats the first part here is the second.

Code:
import java.awt.*;
import javax.swing.*;
import java.applet.AudioClip;
import java.applet.*;
import java.io.*;
import sun.audio.*;
import java.util.StringTokenizer;
import java.net.*;

public class fdoce extends Applet 
{
	static AudioClip sound;
	static ImageIcon christmasBackground;
	static ImageIcon ChristmasBackgroundCutout;
	public String _sound;
	public String CB;
	public String CBC;

    public fdoce() 
    {  
    	      GraphicsEnvironment env =  GraphicsEnvironment.getLocalGraphicsEnvironment();
    		env.getAvailableFontFamilyNames();
    		setFont (new Font("Agency", Font.PLAIN, 12));
    }
    synchronized public void intit()
    {
    	_sound=((_sound=getParameter("sound"))!=null) ? _sound: "";
    	sound=getAudioClip(getCodeBase(), _sound);
    	sound.loop();
    }
    public void paint(Graphics g)
    {
    	g.setColor(Color.WHITE);
    	int length;
    	int chosenDay=0;
    	int tempDay=1;
    	int height=50;
    	int width=50;
    	int numLines=0;
    	boolean commas=true;
    	boolean drumming=false;
    	String title=("12 days of XMAS!\n\n");
    	String lyrics=(Christmas.ChristmasRecursion(0,1,11));
    	StringTokenizer st = new StringTokenizer(lyrics);
    	
    	CB=((_sound=getParameter("image"))!=null)? CB :"christmasBackground.jpg";
    //	CBC=((_sound=getParameter("imageCutout"))!=null)? CBC:"christmasBackgroundCutOut.jpg";
    	christmasBackground=new ImageIcon(CB);
    //	ChristmasBackgroundCutout=new ImageIcon(CBC);
    	
    	g.drawImage(christmasBackground.getImage(),0,0,null);
    	g.drawString(title,10,15);
    	while (st.hasMoreTokens())
    	{
    		String w = st.nextToken();
    		length=w.length();
    		
    		if (w.equalsIgnoreCase("drumming"))
    		{
    			width+=5;
    			drumming=true;
    		}
    		if(drumming==true&& w.equalsIgnoreCase(","))
    		{
    			width+=15;
    			drumming=false;
    		}
    		g.setFont(new Font("Agency", Font.PLAIN, 12));
    			g.drawString(w,width,height);
    			g.setColor(Color.WHITE);
    //			g.drawImage(ChristmasBackgroundCutout.getImage(),725,500,null);
    			g.setColor(Color.WHITE);
    			g.setFont(new Font("Agency", Font.PLAIN, 12));
    			if(w.equalsIgnoreCase(":")||w.equalsIgnoreCase(",")||w.equalsIgnoreCase("!"))
    			{
    				commas=true;
    			}
    			if(commas==false)
    			{
    				g.drawString(w,725,550);
    			}
    			width+=((int)length*5.5+20);
    			if(w.equalsIgnoreCase(":")||w.equalsIgnoreCase(",")||w.equalsIgnoreCase("!"))
    			{
    				numLines++;
    				width=50;
    				height+=15;
    				if(numLines>=37)
    				{
    					width=330;
    				}
    				if(numLines>=74)
    				{
    					width=630;
    				}
    				if(w.equalsIgnoreCase("!"))
    				{
    					g.drawLine(width,height-13,width+275,height-13);
    				}
    			}
    			if(numLines==37||numLines==74)
    			{
    				height=50;
    			}
    			try
				{
					Thread.sleep(400);
				}
				catch(InterruptedException e)
				{
					
				}
				commas=false;	
    			
    			
    	}
    }
    
    
}
your help is greatly appreciated.


thank you.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-22-2008, 02:18 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
It's better that explain your question more specifically. I don't think anyone wants to run your long code and find where the problem is.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a method on original class from created class kpedersen Advanced Java 4 08-20-2008 12:25 AM
Able to find class file in WEB-INF/classes but not after add sub folders in class dir vitalstrike82 Web Frameworks 0 05-13-2008 06:16 AM
Class Reflection: Finding super class names Java Tip java.lang 0 04-23-2008 08:12 PM
what is the Priority for execution of Interface class and a Abstract class Santoshbk Advanced Java 0 04-02-2008 07:04 AM
Merry Christmas and happy New year rgbosque Forum Lobby 3 12-31-2007 02:44 AM


All times are GMT +2. The time now is 01:48 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org