473,322 Members | 1,401 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,322 software developers and data experts.

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

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

private void showLyrics(String myLyrics) {//Class assigned box generator
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));
}

// 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.
Oct 26 '06 #1
5 1602
r035198x
13,262 8TB
Teacher did great in giving you the method. You were then supposed to call it.


Expand|Select|Wrap|Line Numbers
  1. public class TwelveDays {//beginning of the Class of Twelve Days
  2.  
  3. private static void showLyrics(String myLyrics) {//Class assigned box generator**********make it accessible
  4. javax.swing.JTextArea outArea;
  5. javax.swing.JScrollPane scroller;
  6.  
  7. outArea = new javax.swing.JTextArea(20, 35);
  8. outArea.setText(myLyrics);
  9. scroller = new javax.swing.JScrollPane(outArea);
  10. javax.swing.JOptionPane.showMessageDialog(null, scroller,
  11. "The Twelve Days of Technology",
  12. javax.swing.JOptionPane.
  13. INFORMATION_MESSAGE);
  14. } //showLyrics
  15.  
  16. public static void main(String args[]) { //This is the Main Method
  17. // print heading
  18. System.out.println("The Twelve Days of It\n"
  19. + "by John H. Howard\n");
  20.  
  21. // loop through the twelve days
  22. for (int i = 1; i <= 12; i++) {
  23. // print beginning of each day's verse
  24. System.out.println("On the " + chooseDay(i) + " day of It");
  25. System.out.println("My true LOVE of Computers\n" +
  26. "sent to me:");
  27.  
  28. // count down through days already passed in reverse order
  29. // if first day, final verse slightly different
  30. // "A " vs. "and a "
  31. // Eating my own doggie food..
  32. if (i == 1) {
  33. System.out.println("A " + myLyrics(i));
  34. }
  35. else {
  36. for (int j = i; j >= 2; j--) {
  37. System.out.println(myLyrics(j));
  38. }
  39. System.out.println("and A " + myLyrics(1));
  40. TwelveDays.showLyrics(myLyrics(i));// *****************Call the method
  41. }
  42.  
  43. // song done, extra line
  44. System.out.println();
  45. }
  46.  
  47. }
  48.  
  49. public static String chooseDay(int x) { //Method for the days-Case Begins
  50. String day;
  51.  
  52. switch (x) {
  53. case 1:
  54. day = "First";
  55. break;
  56.  
  57. case 2:
  58. day = "Second";
  59. break;
  60.  
  61. case 3:
  62. day = "Third";
  63. break;
  64.  
  65. case 4:
  66. day = "Fourth";
  67. break;
  68.  
  69. case 5:
  70. day = "Fifth";
  71. break;
  72.  
  73. case 6:
  74. day = "Sixth";
  75. break;
  76.  
  77. case 7:
  78. day = "Seventh";
  79. break;
  80.  
  81. case 8:
  82. day = "Eighth";
  83. break;
  84.  
  85. case 9:
  86. day = "Ninth";
  87. break;
  88.  
  89. case 10:
  90. day = "Tenth";
  91. break;
  92.  
  93. case 11:
  94. day = "Eleventh";
  95. break;
  96.  
  97. case 12:
  98. day = "Twelfth";
  99. break;
  100.  
  101. default:
  102. day = "";
  103. break;
  104. }
  105.  
  106. return day;
  107. }
  108.  
  109. public static String myLyrics(int x) { //Method to Reverse Order
  110. String lyrics;
  111.  
  112. switch (x) { //Song Case list
  113. case 1:
  114. lyrics = "one Gig Jump drive";
  115. break;
  116.  
  117. case 2:
  118. lyrics = "Two LCD Monitors";
  119. break;
  120.  
  121. case 3:
  122. lyrics = "Three Floppy disks";
  123. break;
  124.  
  125. case 4:
  126. lyrics = "Four 512Mg SIMM's";
  127. break;
  128.  
  129. case 5:
  130. lyrics = "Five Zip disks";
  131. break;
  132.  
  133. case 6:
  134. lyrics = "Six Tape Drives";
  135. break;
  136.  
  137. case 7:
  138. lyrics = "Seven Java Reference Books";
  139. break;
  140.  
  141. case 8:
  142. lyrics = "Eight External Hard Drives";
  143. break;
  144.  
  145. case 9:
  146. lyrics = "Nine Network ISP's";
  147. break;
  148.  
  149. case 10:
  150. lyrics = "Ten Websites Java Driven";
  151. break;
  152.  
  153. case 11:
  154. lyrics = "Eleven E-Commerce Accounts";
  155. break;
  156.  
  157. case 12:
  158. lyrics = "Twelve Dedicated T3 Lines";
  159. break;
  160.  
  161. default:
  162. lyrics = "";
  163. break;
  164. }
  165.  
  166. return lyrics; //Reverse the Case Display
  167. }
  168. } //This is the end of the Twelve Days of It.
Oct 26 '06 #2
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.
Oct 26 '06 #3
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..
Oct 26 '06 #4
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. public class TwelveDays {//beginning of the Class of Twelve Days
  2.  
  3. private static void showLyrics(String myLyrics) {//Class assigned box generator**********make it accessible
  4. javax.swing.JTextArea outArea;
  5. javax.swing.JScrollPane scroller;
  6.  
  7. outArea = new javax.swing.JTextArea(20, 35);
  8. outArea.setText(myLyrics);
  9. scroller = new javax.swing.JScrollPane(outArea);
  10. javax.swing.JOptionPane.showMessageDialog(null, scroller,
  11. "The Twelve Days of Technology",
  12. javax.swing.JOptionPane.
  13. INFORMATION_MESSAGE);
  14. } //showLyrics
  15.  
  16. public static void main(String args[]) { //This is the Main Method
  17. // print heading
  18. System.out.println("The Twelve Days of It\n"
  19. + "by John H. Howard\n");
  20.  
  21. // loop through the twelve days
  22. String toBeDisplayed = "";
  23.  
  24. for (int i = 1; i <= 12; i++) {
  25. // print beginning of each day's verse
  26. System.out.println("On the " + chooseDay(i) + " day of It");
  27. System.out.println("My true LOVE of Computers\n" +
  28. "sent to me:");
  29.  
  30. // count down through days already passed in reverse order
  31. // if first day, final verse slightly different
  32. // "A " vs. "and a "
  33. // Eating my own doggie food..
  34. if (i == 1) {
  35. System.out.println("A " + myLyrics(i));
  36. }
  37. else {
  38. for (int j = i; j >= 2; j--) {
  39. System.out.println(myLyrics(j));
  40. }
  41. System.out.println("and A " + myLyrics(1));
  42. toBeDisplayed = toBeDisplayed + "\n" + myLyrics(i);
  43. }
  44. // *****************Call the method
  45.  
  46. // song done, extra line
  47. System.out.println();
  48. }
  49. TwelveDays.showLyrics(toBeDisplayed);
  50.  
  51. }
  52.  
  53. public static String chooseDay(int x) { //Method for the days-Case Begins
  54. String day;
  55.  
  56. switch (x) {
  57. case 1:
  58. day = "First";
  59. break;
  60.  
  61. case 2:
  62. day = "Second";
  63. break;
  64.  
  65. case 3:
  66. day = "Third";
  67. break;
  68.  
  69. case 4:
  70. day = "Fourth";
  71. break;
  72.  
  73. case 5:
  74. day = "Fifth";
  75. break;
  76.  
  77. case 6:
  78. day = "Sixth";
  79. break;
  80.  
  81. case 7:
  82. day = "Seventh";
  83. break;
  84.  
  85. case 8:
  86. day = "Eighth";
  87. break;
  88.  
  89. case 9:
  90. day = "Ninth";
  91. break;
  92.  
  93. case 10:
  94. day = "Tenth";
  95. break;
  96.  
  97. case 11:
  98. day = "Eleventh";
  99. break;
  100.  
  101. case 12:
  102. day = "Twelfth";
  103. break;
  104.  
  105. default:
  106. day = "";
  107. break;
  108. }
  109.  
  110. return day;
  111. }
  112.  
  113. public static String myLyrics(int x) { //Method to Reverse Order
  114. String lyrics;
  115.  
  116. switch (x) { //Song Case list
  117. case 1:
  118. lyrics = "one Gig Jump drive";
  119. break;
  120.  
  121. case 2:
  122. lyrics = "Two LCD Monitors";
  123. break;
  124.  
  125. case 3:
  126. lyrics = "Three Floppy disks";
  127. break;
  128.  
  129. case 4:
  130. lyrics = "Four 512Mg SIMM's";
  131. break;
  132.  
  133. case 5:
  134. lyrics = "Five Zip disks";
  135. break;
  136.  
  137. case 6:
  138. lyrics = "Six Tape Drives";
  139. break;
  140.  
  141. case 7:
  142. lyrics = "Seven Java Reference Books";
  143. break;
  144.  
  145. case 8:
  146. lyrics = "Eight External Hard Drives";
  147. break;
  148.  
  149. case 9:
  150. lyrics = "Nine Network ISP's";
  151. break;
  152.  
  153. case 10:
  154. lyrics = "Ten Websites Java Driven";
  155. break;
  156.  
  157. case 11:
  158. lyrics = "Eleven E-Commerce Accounts";
  159. break;
  160.  
  161. case 12:
  162. lyrics = "Twelve Dedicated T3 Lines";
  163. break;
  164.  
  165. default:
  166. lyrics = "";
  167. break;
  168. }
  169.  
  170. return lyrics; //Reverse the Case Display
  171. }
  172. } //This is the end of the Twelve Days of It.
Like this?
Oct 27 '06 #5
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..
Oct 27 '06 #6

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

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
7
by: Advocated | last post by:
Hey all, thanks for taking the time to read this in the first place. Anyway, ill try and keep it simple. In my program, if i type $ man something it should read in the 2 words, man and something...
7
by: Gina_Marano | last post by:
Hey All, Ok, I give up on writing my own FTP component. Too many requirements thrown at me after I started. (you all know how that happens ;) ) I am looking for and FTP component (http...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
1
by: Unebrion | last post by:
Alright im working on a program that prints out user imput in a frame, along with a barcode.. it is like the front of an envelope. Here is the description for the program. This...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.