• Post Reply Bookmark Topic Watch Topic
  • New Topic

I am have 1 issue with my story generator

 
Hank Anderson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
I have one issue with my story generator. I have 4 strings and I do not know how to make the randomly generated story appear in the text field.
When running it in Eclipse the button works but the text is printed in the console.

Here is the code where I am having issues with:
 
Campbell Ritchie
Marshal
Posts: 52590
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Can you make the story appear on System.out? Don't put all that code inside the action performed method; it probably belongs in a class by itself.
 
Hank Anderson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

Can you make the story appear on System.out?


Thank you for the greeting.
By appear in System.out do you mean Eclipses console (I am still new to this so please bare with me)? Yes.
At the moment the generated story does not appear in the textfield but in Eclipses console after pressing the button.

Do not put all that code inside the action performed method; it probably belongs in a class by itself.

I have the code for just generating a story. But how do I extend one class to another to make my GUI work? If that is an option.
 
Campbell Ritchie
Marshal
Posts: 52590
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't. Your class should have a getNextStory() method. All the parts including “The End” should be done by objects of that class. All you have to do is call that method then set the text in your text field.
 
Fred Kleinschmidt
Bartender
Posts: 464
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you want a JTextArea, not a JTextField (A JTextField can contain only one line of text)

Then to fill the text area with your story:

 
Hank Anderson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Issue solved
 
Campbell Ritchie
Marshal
Posts: 52590
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
…and please tell us how you solved it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!