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.

Page 3 of 3 FirstFirst 123
Results 51 to 64 of 64

Thread: dispose(); not working

  1. #51
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dispose(); not working

    haha

    quite a few.
    Last edited by newtolearningjava; April 26th, 2014 at 05:51 PM.

  2. #52
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: dispose(); not working

    Only add the listener once. It will be called for each time it is added.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #53
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dispose(); not working

    please can you show me the line of code you use to only add a listener once?
     
    public class game extends JFrame implements  ActionListener{

    isit like this?

  4. #54
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: dispose(); not working

    It is not possible to control the logic with a single line of code.
    For example: If the addListener() method is in a loop it will be added many times.
    Or if it is in another method that is called many times, it will be called each time.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #55
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dispose(); not working

    how do i change these
    Last edited by newtolearningjava; April 26th, 2014 at 05:52 PM.

  6. #56
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: dispose(); not working

    What good is that? There needs to be code that can be tested.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #57
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dispose(); not working

    if i pits my
    Last edited by newtolearningjava; April 26th, 2014 at 05:52 PM.

  8. #58
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: dispose(); not working

    Find why the actionPerformed() method is called more than once?
    Add a println() next to the line where the addActionListener() method is called to see how many times it is called. If it is called more than once, then you need to move the call to addActionListener() to where it is only called one time.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #59
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dispose(); not working

    Quote Originally Posted by Norm View Post
    Find why the actionPerformed() method is called more than once?
    Add a println() next to the line where the addActionListener() method is called to see how many times it is called. If it is called more than once, then you need to move the call to addActionListener() to where it is only called one time.
    is only ca is only ca
    Last edited by newtolearningjava; April 26th, 2014 at 05:53 PM.

  10. #60
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: dispose(); not working

    Looks like the same listener is added 4 times to 4 different buttons. That wouldn't be a problem if only one button is pressed.

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #61
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dispose(); not working

    I have been playing around with the game. I did what you said and added the system.out.println as you can see in the code below:
    Last edited by newtolearningjava; April 26th, 2014 at 05:53 PM.

  12. #62
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: dispose(); not working

    To see what events are causing the actionPerformed() method to be called, add a println statement to print out the ActionEvent object that is passed to that method. A lot of info will be printed and somewhere in that printout you can see what component sent the event.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #63
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dispose(); not working

    Quote Originally Posted by Norm View Post
    To see what events are causing the actionPerformed() method to be called, add a println statement to print out the ActionEvent object that is passed to that method. A lot of info will be printed and somewhere in that printout you can see what component sent the event.
    Any soloution for this?
    Last edited by newtolearningjava; April 26th, 2014 at 05:54 PM.

  14. #64
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,140
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: dispose(); not working

    Did you look at what was printed out in the actionPerformed() method to see what component sent the ActionEvent?

    I've lost my version of the source for this problem. I can't compile and execute it for testing.
    If you don't understand my answer, don't ignore it, ask a question.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Replies: 7
    Last Post: April 25th, 2013, 01:12 PM
  2. Syntax error with dispose()
    By jagnat in forum AWT / Java Swing
    Replies: 1
    Last Post: October 14th, 2011, 11:00 AM
  3. dispose()'ing a JFrame and replacing it
    By musasabi in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 14th, 2010, 02:31 PM
  4. Replies: 4
    Last Post: January 26th, 2009, 11:03 PM