Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 9 Online
OpenStudy (woodrow73):

Updated to include the source code-- perhaps for inspiration. Here's the question: How do I display 5 string variables in a window / gui-type display? - not sure how I should go about this.. - as my knowledge of swing/awt/javafx is limited. But the goal seems simple enough- just not sure which commands to use.

OpenStudy (woodrow73):

I've developed a program that asks the user wether they would like to create a fortune cookie, or draw a random fortune cookie. All created fortune cookies are appended to a .txt document (new fortune cookies are added on) via the File, PrintWriter, FileWriter classes. If the user chooses to draw a random fortune cookie, it will extract a random one from the .txt document, and extract that fortune cookie into 5 separate strings (one for each line).

OpenStudy (woodrow73):

If you care to know, the random number generator will pick a random number, and that number will represent which numbered fortune will be extracted. Since the number of fortunes can vary- the range of the random number generator is a function of how many lines there are in the .txt document (1 fortune = 5 lines long). With a simple enough algorithm, I can translate the random number into which numbered line I should start reading the 5 lines from- -And so I have a randomly picked fortune saved into 5 string variables. cheers - woodrow73.

OpenStudy (woodrow73):

Source code for fortune cookie program:

OpenStudy (woodrow73):

Source code v2.0 includes different types of input validation: should be crash proof;

OpenStudy (e.mccormick):

I did not go through all your code, but from the header part it looks like you are going th correct direction to display strings with swing. http://www.tutorialspoint.com/javaexamples/gui_rectangle.htm

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!