Results 1 to 18 of 18
  1. #1
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Talking how to get only one "ok" window!

    hi
    i'm new to java, and i want to ask a bizarre question! :D
    i'm using a program that generates some files, for example 5 files, the problem that in the program i must clic on "ok" message to generate the second file; ie: the program waits till i'll clic on 'ok' to increment the loop (for)....
    is it a way to make this to have only ONE OK?
    i've tried a hack, is by using a loop, (N-1) that makes as i pressed "Enter" and the the latest N will be the latest 'ok' that the user will push .... but as am beginner i can't code it lool
    but, is it a way to make this "ok" appear only once a time?
    i use JCreator LE.
    thanks in advance :cool:

  2. #2
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    erm

    put the ok message in an if statment so that in only runs once the loop has finished.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  3. #3
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    thank you alacn
    but the problem, with the if statement, there is no condition to make the break, i've thaught about this, is to make some thing to make the loop exit and go directly to the ok message....
    but with the for we have a number of file "parsing" and a number of generated files, so i think the for is the loop that is needed?

  4. #4
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    can you post your code please

    and yeah i would use a for loop to loop through all files and then use the counter viarable to check once the last file in the loop has been reach with an if statment, then display the message.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  5. #5
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    The simplest solution (if I understand your problem correctly) is to use a JOptionPane for your OK button. As a modal dialog it should halt Swing actions until it has been dealt with.

    If this doesn't answer your question, you may need to give more detail.

  6. #6
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by alacn View Post
    can you post your code please

    and yeah i would use a for loop to loop through all files and then use the counter viarable to check once the last file in the loop has been reach with an if statment, then display the message.
    thank you alacn, i think it's a good idea, i'll give it a try :D
    Quote Originally Posted by curmudgeon View Post
    The simplest solution (if I understand your problem correctly) is to use a JOptionPane for your OK button. As a modal dialog it should halt Swing actions until it has been dealt with.

    If this doesn't answer your question, you may need to give more detail.
    thank you curmudgeon, here i've not the entire code, it is on the other computer, tomorrow i'll test it and i'll give you the answer and more details :)


    thank you again for helping me :)

  7. #7
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    hi,
    here i'm again :D
    about the "JOptionPane" instruction, i used it, but it's the same problem!!!
    the program waits till i press ok to continue working in the loop! i want to continue the loop without waiting to press ok :(
    is it possible :(
    is there any instruction to tell java to do this:
    generates all file and then show the ok dialog (and not every time you generate a file you show me the ok message and you wait till i press ok to generate the second one)

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default

    i want to continue the loop without waiting to press ok
    What then is the purpose of asking the question if the loop is to continue without the answer?

  9. #9
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What then is the purpose of asking the question if the loop is to continue without the answer?
    hi :D
    the problem is that the program will generate some files, it parses xml files and generates other files, so if you have 5 files, it will generate 5 other files, and of course it will display 5 ok messages, so imagine the user wants to parse 1000 xml!!!! so he must stay near to the screen clicking every time on ok :eek:

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default

    Why ask any questions at all?
    Or only one before starting?

  11. #11
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    heuuuuuuuuu????????????
    sorry, but i dont understand here...which question?

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default

    The question the prompt asks: Is it OK to ...

    Another idea:
    The JOptionPane has several different formats for display info and asking questions. One of them allows you to get different answers to your question.
    You could ask the user if its OK to do one more or if its OK to do ALL of the rest. If the user says ALL of the rest, you set a boolean to remember that and do NOT ask again.

  13. #13
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Code is good... really helps us more than you explaining ever will :P

    Anyway, why not put the loop in its own method, and use JOptionPane before calling that method? Pseudocode...

    Java Code:
    method that starts process (confirmAndCreate):
    show JOptionPane to confirm
    if ok was clicked then:
         call createFiles
    else return
    
    method that creates files (createFiles):
    for file in filesToParse
         parse file
         create new file(s)
    return
    hopefully this helps :D
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  14. #14
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    thank you, and sorry if i took long time to reply, i opologize :o
    Quote Originally Posted by Norm View Post
    The question the prompt asks: Is it OK to ...

    Another idea:
    The JOptionPane has several different formats for display info and asking questions. One of them allows you to get different answers to your question.
    You could ask the user if its OK to do one more or if its OK to do ALL of the rest. If the user says ALL of the rest, you set a boolean to remember that and do NOT ask again.
    thanks for the idea, but the problem is that (or we, because am not the only one on the project) are beginners in java coding!!! so how do i put the boolean?
    Quote Originally Posted by Singing Boyo View Post
    Code is good... really helps us more than you explaining ever will :P

    Anyway, why not put the loop in its own method, and use JOptionPane before calling that method? Pseudocode...

    Java Code:
    method that starts process (confirmAndCreate):
    show JOptionPane to confirm
    if ok was clicked then:
         call createFiles
    else return
    
    method that creates files (createFiles):
    for file in filesToParse
         parse file
         create new file(s)
    return
    hopefully this helps :D
    heuuuuuuuuuuuu!!!!
    thanks for the code!!!
    i'll try it tomorrow because the entire code is not with me, i'll try it and give the answer tomorrow :)

    thanks again for the help :D

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default

    pseudo code:
    Java Code:
    boolean askQues = true;  // boolean to control whether to ask user the question
    
    Begin loop for writing files {
      if(askQues) {
       Ask question to user: Ok to write one or all or ???
       if (response == OK to write all)
         askQues = false;  // remember to not ask this question again
       .. handle other possible responses
      }
       ...
       create and write file
    }  // end loop for creating and writing files

  16. #16
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    Quote Originally Posted by abdoubb View Post
    hi :D
    the problem is that the program will generate some files, it parses xml files and generates other files, so if you have 5 files, it will generate 5 other files, and of course it will display 5 ok messages, so imagine the user wants to parse 1000 xml!!!! so he must stay near to the screen clicking every time on ok :eek:
    You just put this "OK" statement right outside the loop at all.

    Java Code:
    for(...;...;...)
    {
    ...
    try{}
    catch(Exception e)
    {
     JOptionPane.showMessageDialog(this,"file "+file+": IO error");
     continue;
    }
    
    }
    JOptionPane.showMessageDialog(this,"OK");
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  17. #17
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    thank you !!! really thanks for the help!!!
    Quote Originally Posted by Norm View Post
    pseudo code:
    Java Code:
    boolean askQues = true;  // boolean to control whether to ask user the question
    
    Begin loop for writing files {
      if(askQues) {
       Ask question to user: Ok to write one or all or ???
       if (response == OK to write all)
         askQues = false;  // remember to not ask this question again
       .. handle other possible responses
      }
       ...
       create and write file
    }  // end loop for creating and writing files
    thank you, i'll try the code, and as i said am not the real coder, so i must give the code the the coder to test it!!! in java am dumb :(
    Quote Originally Posted by Webuser View Post
    You just put this "OK" statement right outside the loop at all.

    Java Code:
    for(...;...;...)
    {
    ...
    try{}
    catch(Exception e)
    {
     JOptionPane.showMessageDialog(this,"file "+file+": IO error");
     continue;
    }
    
    }
    JOptionPane.showMessageDialog(this,"OK");
    we tried to put the ok dialog at the end of the loop but it dident work! it generated only one file!!!! bizarre! :eek:
    thank's for the code, we'll try this!! maybe it will work :cool: (and am sure it will do) :D
    Last edited by abdoubb; 06-24-2010 at 11:14 PM.

  18. #18
    abdoubb is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    hi and sorry for being to late!
    i just wanna thank every one who helped me! we've finally let the "ok" message because when executing the program it is something like "slow" so imagine if we made a batch with dozen of files!
    thanks again and sorry :)

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  3. problem with argument list and precedence "(" and ")"
    By helpisontheway in forum Advanced Java
    Replies: 6
    Last Post: 12-24-2009, 07:50 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •