473,805 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need imput in box

14 New Member
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.
Oct 26 '06 #1
5 1626
r035198x
13,262 MVP
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
jhhbr549
14 New Member
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
jhhbr549
14 New Member
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 MVP
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
jhhbr549
14 New Member
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
2476
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 last year we got traffic of between 2000 - 2500 unique visitors per day. We are now about to re-launch the site from Sweden and we need to purchase a script to run it. Having looked at what is available on the net I have realised that we need a...
6
2189
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
2447
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 parse them to have a tree representation such as :
7
4393
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 few features that you'd expect in any editor, except nearly none of them seem to have: 1 - Search and repalce with Regular Expressions. 2 - Search and Replace in an Xpath context. 3 - User specified tag-generation for either on a...
8
2851
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 list class must Ioverride in order for this to work?
3
2642
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 you need more detail I can be glad to prove all my points. Our goal is to make logical systems. We don't want php,perl, or c++ making all the procedure calls and having the host language to be checking for errors and handleing all the...
7
1586
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 it should look up man - find that its a function, run the man function, and then, with that second word "something" it should then execute that as its parameters, if that make sense. At the moment, it semi works, i.e If i type man it will run...
7
1364
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 download would be a plu as well). Here are the requirements:
0
3969
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 Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
1
3140
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 part just explains a check digit.. i think this part in my program is alright These barcodes actually have four parts: a tall line as the first bar, a series of tall and short lines corresponding to the digits in the ZIP code, a check digit,...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.