• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

User-Selected Loop Length/Two Methods in Main

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great thanks!
 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic