Need imput in box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jhhbr549
    New Member
    • Oct 2006
    • 14

    #1

    Need imput in box

    I have a problem. My teacher of Java is jumping all over the book and then gave us this project. Well I got the project to run. But he wants the output in a box with an ok button on it. He gave us the code and said just put it in the class and it will do the rest. Well as you guessed it does not. please look at this and let me know how to get it in the box.

    Thanks John- JHHBR549@aol.co m

    public class TwelveDays {//beginning of the Class of Twelve Days

    private void showLyrics(Stri ng myLyrics) {//Class assigned box generator
    javax.swing.JTe xtArea outArea;
    javax.swing.JSc rollPane scroller;

    outArea = new javax.swing.JTe xtArea(20, 35);
    outArea.setText (myLyrics);
    scroller = new javax.swing.JSc rollPane(outAre a);
    javax.swing.JOp tionPane.showMe ssageDialog(nul l, scroller,
    "The Twelve Days of Technology",
    javax.swing.JOp tionPane.
    INFORMATION_MES SAGE);
    } //showLyrics

    public static void main(String args[]) { //This is the Main Method
    // print heading
    System.out.prin tln("The Twelve Days of It\n"
    + "by John H. Howard\n");

    // loop through the twelve days
    for (int i = 1; i <= 12; i++) {
    // print beginning of each day's verse
    System.out.prin tln("On the " + chooseDay(i) + " day of It");
    System.out.prin tln("My true LOVE of Computers\n" +
    "sent to me:");

    // count down through days already passed in reverse order
    // if first day, final verse slightly different
    // "A " vs. "and a "
    // Eating my own doggie food..
    if (i == 1) {
    System.out.prin tln("A " + myLyrics(i));
    }
    else {
    for (int j = i; j >= 2; j--) {
    System.out.prin tln(myLyrics(j) );
    }
    System.out.prin tln("and A " + myLyrics(1));
    }

    // song done, extra line
    System.out.prin tln();
    }
    }

    public static String chooseDay(int x) { //Method for the days-Case Begins
    String day;

    switch (x) {
    case 1:
    day = "First";
    break;

    case 2:
    day = "Second";
    break;

    case 3:
    day = "Third";
    break;

    case 4:
    day = "Fourth";
    break;

    case 5:
    day = "Fifth";
    break;

    case 6:
    day = "Sixth";
    break;

    case 7:
    day = "Seventh";
    break;

    case 8:
    day = "Eighth";
    break;

    case 9:
    day = "Ninth";
    break;

    case 10:
    day = "Tenth";
    break;

    case 11:
    day = "Eleventh";
    break;

    case 12:
    day = "Twelfth";
    break;

    default:
    day = "";
    break;
    }

    return day;
    }

    public static String myLyrics(int x) { //Method to Reverse Order
    String lyrics;

    switch (x) { //Song Case list
    case 1:
    lyrics = "one Gig Jump drive";
    break;

    case 2:
    lyrics = "Two LCD Monitors";
    break;

    case 3:
    lyrics = "Three Floppy disks";
    break;

    case 4:
    lyrics = "Four 512Mg SIMM's";
    break;

    case 5:
    lyrics = "Five Zip disks";
    break;

    case 6:
    lyrics = "Six Tape Drives";
    break;

    case 7:
    lyrics = "Seven Java Reference Books";
    break;

    case 8:
    lyrics = "Eight External Hard Drives";
    break;

    case 9:
    lyrics = "Nine Network ISP's";
    break;

    case 10:
    lyrics = "Ten Websites Java Driven";
    break;

    case 11:
    lyrics = "Eleven E-Commerce Accounts";
    break;

    case 12:
    lyrics = "Twelve Dedicated T3 Lines";
    break;

    default:
    lyrics = "";
    break;
    }

    return lyrics; //Reverse the Case Display
    }
    } //This is the end of the Twelve Days of It.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Teacher did great in giving you the method. You were then supposed to call it.


    Code:
    public class TwelveDays {//beginning of the Class of Twelve Days
    
    private static void showLyrics(String myLyrics) {//Class assigned box generator**********make it accessible
    javax.swing.JTextArea outArea;
    javax.swing.JScrollPane scroller;
    
    outArea = new javax.swing.JTextArea(20, 35);
    outArea.setText(myLyrics);
    scroller = new javax.swing.JScrollPane(outArea);
    javax.swing.JOptionPane.showMessageDialog(null, scroller,
    "The Twelve Days of Technology",
    javax.swing.JOptionPane.
    INFORMATION_MESSAGE);
    } //showLyrics
    
    public static void main(String args[]) { //This is the Main Method
    // print heading
    System.out.println("The Twelve Days of It\n"
    + "by John H. Howard\n");
    
    // loop through the twelve days
    for (int i = 1; i <= 12; i++) {
    // print beginning of each day's verse
    System.out.println("On the " + chooseDay(i) + " day of It");
    System.out.println("My true LOVE of Computers\n" +
    "sent to me:");
    
    // count down through days already passed in reverse order
    // if first day, final verse slightly different
    // "A " vs. "and a "
    // Eating my own doggie food..
    if (i == 1) {
    System.out.println("A " + myLyrics(i));
    }
    else {
    for (int j = i; j >= 2; j--) {
    System.out.println(myLyrics(j));
    }
    System.out.println("and A " + myLyrics(1));
    TwelveDays.showLyrics(myLyrics(i));// *****************Call the method
    }
    
    // song done, extra line
    System.out.println();
    }
    
    }
    
    public static String chooseDay(int x) { //Method for the days-Case Begins
    String day;
    
    switch (x) {
    case 1:
    day = "First";
    break;
    
    case 2:
    day = "Second";
    break;
    
    case 3:
    day = "Third";
    break;
    
    case 4:
    day = "Fourth";
    break;
    
    case 5:
    day = "Fifth";
    break;
    
    case 6:
    day = "Sixth";
    break;
    
    case 7:
    day = "Seventh";
    break;
    
    case 8:
    day = "Eighth";
    break;
    
    case 9:
    day = "Ninth";
    break;
    
    case 10:
    day = "Tenth";
    break;
    
    case 11:
    day = "Eleventh";
    break;
    
    case 12:
    day = "Twelfth";
    break;
    
    default:
    day = "";
    break;
    }
    
    return day;
    }
    
    public static String myLyrics(int x) { //Method to Reverse Order
    String lyrics;
    
    switch (x) { //Song Case list
    case 1:
    lyrics = "one Gig Jump drive";
    break;
    
    case 2:
    lyrics = "Two LCD Monitors";
    break;
    
    case 3:
    lyrics = "Three Floppy disks";
    break;
    
    case 4:
    lyrics = "Four 512Mg SIMM's";
    break;
    
    case 5:
    lyrics = "Five Zip disks";
    break;
    
    case 6:
    lyrics = "Six Tape Drives";
    break;
    
    case 7:
    lyrics = "Seven Java Reference Books";
    break;
    
    case 8:
    lyrics = "Eight External Hard Drives";
    break;
    
    case 9:
    lyrics = "Nine Network ISP's";
    break;
    
    case 10:
    lyrics = "Ten Websites Java Driven";
    break;
    
    case 11:
    lyrics = "Eleven E-Commerce Accounts";
    break;
    
    case 12:
    lyrics = "Twelve Dedicated T3 Lines";
    break;
    
    default:
    lyrics = "";
    break;
    }
    
    return lyrics; //Reverse the Case Display
    }
    } //This is the end of the Twelve Days of It.

    Comment

    • jhhbr549
      New Member
      • Oct 2006
      • 14

      #3
      Thanks the box comes up now, but now in the box only prints one line of the second case untill you press the ok button. then the next line then ok and so on. I need all the out put in the box at one time with a scroll bar and only hit ok once. The output also still prints correctly before the box appears.

      Help.

      Comment

      • jhhbr549
        New Member
        • Oct 2006
        • 14

        #4
        Is there a way to put the output in a building array that would only generate one output? I think that needs to be the fix, but not sure.

        Like an array with 12 objects

        or maybe just one object that gets the new loop output added to the end and then called to the method.

        Not sure what path to take. The code is real close. tring not to mess it up.

        The println output is good. i just need

        this:

        The Twelve Days of It
        by John H. Howard

        On the First day of It
        My true LOVE of Computers
        sent to me:
        A one Gig Jump drive

        On the Second day of It
        My true LOVE of Computers
        sent to me:
        Two LCD Monitors
        and A one Gig Jump drive

        On the Third day of It
        My true LOVE of Computers
        sent to me:
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Fourth day of It
        My true LOVE of Computers
        sent to me:
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Fifth day of It
        My true LOVE of Computers
        sent to me:
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Sixth day of It
        My true LOVE of Computers
        sent to me:
        Six Tape Drives
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Seventh day of It
        My true LOVE of Computers
        sent to me:
        Seven Java Reference Books
        Six Tape Drives
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Eighth day of It
        My true LOVE of Computers
        sent to me:
        Eight External Hard Drives
        Seven Java Reference Books
        Six Tape Drives
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Ninth day of It
        My true LOVE of Computers
        sent to me:
        Nine Network ISP's
        Eight External Hard Drives
        Seven Java Reference Books
        Six Tape Drives
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Tenth day of It
        My true LOVE of Computers
        sent to me:
        Ten Websites Java Driven
        Nine Network ISP's
        Eight External Hard Drives
        Seven Java Reference Books
        Six Tape Drives
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Eleventh day of It
        My true LOVE of Computers
        sent to me:
        Eleven E-Commerce Accounts
        Ten Websites Java Driven
        Nine Network ISP's
        Eight External Hard Drives
        Seven Java Reference Books
        Six Tape Drives
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        On the Twelfth day of It
        My true LOVE of Computers
        sent to me:
        Twelve Dedicated T3 Lines
        Eleven E-Commerce Accounts
        Ten Websites Java Driven
        Nine Network ISP's
        Eight External Hard Drives
        Seven Java Reference Books
        Six Tape Drives
        Five Zip disks
        Four 512Mg SIMM's
        Three Floppy disks
        Two LCD Monitors
        and A one Gig Jump drive

        in the box that is generated by the first code.

        Help..

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Code:
          public class TwelveDays {//beginning of the Class of Twelve Days
          
          private static void showLyrics(String myLyrics) {//Class assigned box generator**********make it accessible
          javax.swing.JTextArea outArea;
          javax.swing.JScrollPane scroller;
          
          outArea = new javax.swing.JTextArea(20, 35);
          outArea.setText(myLyrics);
          scroller = new javax.swing.JScrollPane(outArea);
          javax.swing.JOptionPane.showMessageDialog(null, scroller,
          "The Twelve Days of Technology",
          javax.swing.JOptionPane.
          INFORMATION_MESSAGE);
          } //showLyrics
          
          public static void main(String args[]) { //This is the Main Method
          // print heading
          System.out.println("The Twelve Days of It\n"
          + "by John H. Howard\n");
          
          // loop through the twelve days
          String toBeDisplayed = "";
          
          for (int i = 1; i <= 12; i++) {
          // print beginning of each day's verse
          System.out.println("On the " + chooseDay(i) + " day of It");
          System.out.println("My true LOVE of Computers\n" +
          "sent to me:");
          
          // count down through days already passed in reverse order
          // if first day, final verse slightly different
          // "A " vs. "and a "
          // Eating my own doggie food..
          if (i == 1) {
          System.out.println("A " + myLyrics(i));
          }
          else {
          for (int j = i; j >= 2; j--) {
          System.out.println(myLyrics(j));
          }
          System.out.println("and A " + myLyrics(1));
          toBeDisplayed = toBeDisplayed + "\n" + myLyrics(i);
          }
          // *****************Call the method
          
          // song done, extra line
          System.out.println();
          }
          TwelveDays.showLyrics(toBeDisplayed);
          
          }
          
          public static String chooseDay(int x) { //Method for the days-Case Begins
          String day;
          
          switch (x) {
          case 1:
          day = "First";
          break;
          
          case 2:
          day = "Second";
          break;
          
          case 3:
          day = "Third";
          break;
          
          case 4:
          day = "Fourth";
          break;
          
          case 5:
          day = "Fifth";
          break;
          
          case 6:
          day = "Sixth";
          break;
          
          case 7:
          day = "Seventh";
          break;
          
          case 8:
          day = "Eighth";
          break;
          
          case 9:
          day = "Ninth";
          break;
          
          case 10:
          day = "Tenth";
          break;
          
          case 11:
          day = "Eleventh";
          break;
          
          case 12:
          day = "Twelfth";
          break;
          
          default:
          day = "";
          break;
          }
          
          return day;
          }
          
          public static String myLyrics(int x) { //Method to Reverse Order
          String lyrics;
          
          switch (x) { //Song Case list
          case 1:
          lyrics = "one Gig Jump drive";
          break;
          
          case 2:
          lyrics = "Two LCD Monitors";
          break;
          
          case 3:
          lyrics = "Three Floppy disks";
          break;
          
          case 4:
          lyrics = "Four 512Mg SIMM's";
          break;
          
          case 5:
          lyrics = "Five Zip disks";
          break;
          
          case 6:
          lyrics = "Six Tape Drives";
          break;
          
          case 7:
          lyrics = "Seven Java Reference Books";
          break;
          
          case 8:
          lyrics = "Eight External Hard Drives";
          break;
          
          case 9:
          lyrics = "Nine Network ISP's";
          break;
          
          case 10:
          lyrics = "Ten Websites Java Driven";
          break;
          
          case 11:
          lyrics = "Eleven E-Commerce Accounts";
          break;
          
          case 12:
          lyrics = "Twelve Dedicated T3 Lines";
          break;
          
          default:
          lyrics = "";
          break;
          }
          
          return lyrics; //Reverse the Case Display
          }
          } //This is the end of the Twelve Days of It.
          Like this?

          Comment

          • jhhbr549
            New Member
            • Oct 2006
            • 14

            #6
            Makes me closer but missing the heading and it is to print all twelve days in the box. With a scroll bar..

            The output needs to be in a box. heading and then heading for beginning of each song and then each day . I am still having trouble.

            Any help..

            Comment

            Working...