Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Lock up code to the click of a button!!!

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Location
    Italy - Campania - Avellino
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Lock up code to the click of a button!!!

    Hi All!!
    I'm new in this forum. My name is Mauro and i'm italian, so... sorry for my english >_<

    The question of this post is:
    My professor wants us to not use JOptionPane to display inputdialog, and he wants us to create a small window where you can enter for example the name of a file to open and/or load.
    So what did I do, I create a class, i implemented ActionListener listeners for events and extend the class with JFrame, and in the constructor I build my beautiful window. So far so good, it creates, and I can manage it completely.
    Now comes the fun part.
    If I put in the main by, for example:
    IG_MiniFrame frmCorridoi = new IG_MiniFrame("Numero Corridoi!", 300, 200, 260, 100, "Numero Corridoi:");
    IG_MiniFrame frmFile = new IG_MiniFrame("Numero File!", 300, 200, 260, 100, "Numero File:");
    IG_MiniFrame frmPosti = new IG_MiniFrame("Numero Posti!", 300, 200, 260, 100, "Numero Posti:");
    the program of course, continue to run the underlying code, without stopping to wait for me to insert a given value in the JTextField.
    I remedied this with a horrid, ugly, that goes against my way of programming, but I only found this method, and that is to put a while loop that loops until I press the OK button of the window that I change a Boolean variable to true and will continue the main and open another window:
    IG_MiniFrame frmCorridoi = new IG_MiniFrame("Numero Corridoi!", 300, 200, 260, 100, "Numero Corridoi:");
    while(frmCorridoi.getComplete()==false){}
    IG_MiniFrame frmFile = new IG_MiniFrame("Numero File!", 300, 200, 260, 100, "Numero File:");
    while(frmFile.getComplete()==false){}
    IG_MiniFrame frmPosti = new IG_MiniFrame("Numero Posti!", 300, 200, 260, 100, "Numero Posti:");
    while(frmPosti.getComplete()==false){}
    What I ask is: is there a more "beautiful" to program such a thing? lock code until you enter the value in the text?
    It would take a good method in the actionperformed type:
    main.continue(); XD
    and of course in the constructor main.stop(); >_>


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Lock up code to the click of a button!!!

    Allen Walker posts a question from an Italian called Mauro? WTF?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: Lock up code to the click of a button!!!

    is there a more "beautiful" to program such a thing? lock code until you enter the value in the text?
    Does "lock code" mean you want to block execution?
    If you use a modal dialog, you could keep the user in the dialog until there is a correct answer or cancellation.

Similar Threads

  1. [SOLVED] Servlet cant perform sql after second button click
    By Stefan_Lam in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 31st, 2011, 06:18 AM
  2. [SOLVED] Click button to open JDialog
    By susieferrari in forum Java Theory & Questions
    Replies: 6
    Last Post: March 30th, 2011, 10:24 AM
  3. How to code "check button"
    By Suni in forum AWT / Java Swing
    Replies: 1
    Last Post: December 28th, 2010, 09:21 AM
  4. need to add a Double Button to the code
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: August 5th, 2010, 12:19 PM
  5. close JDialog on button click
    By Christophe in forum AWT / Java Swing
    Replies: 4
    Last Post: April 5th, 2010, 12:04 AM