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 9 of 9

Thread: Closing dialog box

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Closing dialog box

    Hi,

    I'm doing some practice on dialog boxes and I have a problem with closing them after introducing text in the TextField.
    So, the dialog box is showing when clicking the right button, but isn't closing after clicking "OK" button.

    l = a label with some text.
    dl = dialog box.
    tf = TextField in the dl.

    What am I doing wrong?


    public boolean action(Event evt, Object arg){
    String btn = (String)arg;
    if (evt.target instanceof Button)
    l.setText(tf.getText());
    dl.hide();
     
    return true;
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Closing dialog box

    JavaScript?

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Closing dialog box

    No, just Java.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Closing dialog box

    Can you post a small program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Closing dialog box

    I'm not familiar with the Event class in Java, and therefore don't recognize evt.target. The action() method also appears to be a custom event handling implementation, so I'm not sure what's going on there. Also, you should be using the more modern JButton rather than Button, JLabel, JTextField, etc. Are you using a very old tutorial? Can you provide a reference or link to the material you're studying?

    Try this tutorial on the subject.

  6. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Closing dialog box

    It's a 1996 book, so yes.. pretty old but it gives me the chance to consult the Java API and do more basic and manual stuffs.
    It's not the best book, but still something to learn from. If you could recommend me something else, please do so.

    As with the code, I tried that tutorial from oracle, and it worked, but still have no clue why my code didn't work. Anyway, I'll try to figure it out later, and will use the JOptionPane from now on.

    Norm, I guess there's no point in writing a program using that snippet of code since I got it working with the above tutorial.

    Please recommend me some another usefull books, This is the current book I'm learning from, and I almost read it all, so some new lecture would be great. http://portal.aauj.edu/e_books/teach...in_21_days.pdf

    Thanks.

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Closing dialog box

    It's a 1996 book, so yes.. pretty old but it gives me the chance to consult the Java API and do more basic and manual stuffs.
    It's too old. The language has changed a lot in 18 years, and there's no good reason to be using a book that old. A modern book or study guide will give you the same chance to consult and learn the modern API and the API will actually look familiar when you get there instead of completely foreign as it likely does with a book that old.

    JOptionPanes are not always the answer. They're a tool you should be aware of and are equivalent to what I think you were doing in the book you were reading. I've no idea why your code didn't work, but it's so old that today's compilers are probably not handling it correctly, and knowing why it didn't work would only be helpful if you wanted to be a programmer in the 1990s. It's time to move on.

    This free, online/downloadable book is an excellent study guide. You should already have some programming basics from the old book you've been using, so you may want to skim the first 2 or 3 chapters. After that I recommend you dig in, start reading thoroughly, type out every example and do every chapter exercise, and come here when you need help. If you suspect you missed something important in an earlier chapter, go back and cover it more thoroughly.

    Welcome to the next century.

  8. #8
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Closing dialog box

    Thank you for the book and advices. I'll switch to it.

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Closing dialog box

    You're welcome, and good luck!

Similar Threads

  1. Java Dialog Box HELP
    By Green Light in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 1st, 2013, 02:33 AM
  2. Help formatting Dialog box!
    By swirth123 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 24th, 2013, 03:20 PM
  3. Making an input dialog box appear after closing a combo box
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 14
    Last Post: November 11th, 2012, 06:22 PM
  4. Saving a file using a dialog box
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 5th, 2010, 05:21 PM
  5. [SOLVED] Help with dialog box
    By 03EVOAWD in forum AWT / Java Swing
    Replies: 5
    Last Post: August 4th, 2009, 11:06 AM