Results 1 to 2 of 2

Thread: christmas class

  1. #1
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    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.

    Java 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.

    Java 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.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 01:25 AM
  2. Replies: 0
    Last Post: 05-13-2008, 07:16 AM
  3. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 09:12 PM
  4. Replies: 0
    Last Post: 04-02-2008, 08:04 AM
  5. Merry Christmas and happy New year
    By rgbosque in forum Forum Lobby
    Replies: 3
    Last Post: 12-31-2007, 03:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •