• Post Reply Bookmark Topic Watch Topic
  • New Topic

User-Selected Loop Length/Two Methods in Main  RSS feed

 
Christian Somody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know if there is a way for a showConfirmDialog() to appear and ask if somebody would like to do something. Then if "yes" is clicked, it creates a showInputDialog() and goes back to another showConfirmDialog() afterwards (possibly infinitely). If "no" is clicked on the confirmDialog, it does something different. This is my code so far.



I made a comment in the code where the call (whatever it may be) should go. I'm thinking along the lines of the driver having another method in it that includes the showConfirmDialog call that we can call in main()'s if statement. Good idea?
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common idiom for this type of endeavor is to use a while loop:


[ January 22, 2007: Message edited by: Garrett Rowe ]
 
Christian Somody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am aware of the while loop but I can't see how I could apply it to my situation.
[ January 22, 2007: Message edited by: Christian Somody ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's pseudocode:


in English:

ask the user if they want to input another position. as long as they say "yes", you want to do your code again.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And here's an example of a program that executes until the user chooses to end it:



[edit: fixed broken code... apparently Scanner.nextline() doesn't block ?!?]
[ January 22, 2007: Message edited by: Garrett Rowe ]
 
Christian Somody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!