Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: 12 days of xmas??? not showing

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 12 days of xmas??? not showing

    i wrote this but my song isnt showing up.
    import javax.swing.*;
     
    public class Assign5 {
     
       public static void main( String args[] )
       {
          String result = "";
          JTextArea songArea = new JTextArea(20, 30);
          JScrollPane scroller = new JScrollPane(songArea);
          String songString = "";
     
          for ( int day = 1; day <= 12; day++ ) {
              result += "\nOn the " + day;
     
              switch( day ) {
                 case 1:
                    result += "st";
                    break;            
                 case 2:
                    result += "nd";
                    break;  
                 case 3:
                    result += "rd";
                    break;  
                 default: 
                    result += "th";
                    break;
              }
              result += " day of Christmas, my true love gave to me: ";
     
              switch( day ) {
                 case 12:
                    result += "   Twelve lords-a-leaping, ";
                 case 11:
                    result += "   Eleven pipers piping, ";
                 case 10:
                    result += "   Ten drummers drumming, ";
                 case 9:
                    result += "   Nine ladies dancing, ";
                 case 8:
                    result += "   Eight maids-a-milking, ";
                 case 7:
                    result += "   Seven swans-a-swimming, ";
                 case 6:
                    result += "   Six geese-a-laying, ";
                 case 5:
                    result += "   Five golden rings.";
                 case 4:
                    result += "   Four calling birds, ";
                 case 3:
                    result += "   Three French hens, ";
                 case 2:
                    result += "   Two turtle doves, and ";
                 case 1:
                    result += "   a Partridge in pear tree.";          
              }
          }
     
          songArea.setText(songString);
          JOptionPane.showMessageDialog(null, scroller, "Twelve Days of Christmas", 
        		    JOptionPane.PLAIN_MESSAGE);
          System.exit( 0 );
       }
    }
    Last edited by copeg; March 9th, 2011 at 09:41 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: 12 days of xmas??? not showing

    For future reference, please flank your code with the code/highlight tags (see Announcements - What's Wrong With My Code? for instructions). I've edited your post for you this time.

    Now to the problem...you've set the JTextArea text to the variable songString - look closely at the code and determine what this variable's value might be. To be sure, add a System.out.println statement to print out songString and see what its value is...and at the same time, add another System.out.println statement to print out the variable result.

Similar Threads

  1. Label not showing up.
    By joshft91 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 1st, 2011, 03:36 PM
  2. showMessageDialog is not showing!
    By jonathan920 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2010, 04:14 AM
  3. Calculating Business days in java
    By narranil2 in forum Algorithms & Recursion
    Replies: 2
    Last Post: August 17th, 2010, 12:08 PM
  4. Getting date based on days past year
    By aussiemcgr in forum Java Theory & Questions
    Replies: 3
    Last Post: July 14th, 2010, 04:06 PM
  5. how do i get only the workig days for a certain month
    By anonimus83 in forum Algorithms & Recursion
    Replies: 2
    Last Post: January 11th, 2010, 11:13 AM