Search:

Type: Posts; User: Norm

Search: Search took 0.11 seconds.

  1. Replies
    63
    Views
    7,385

    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...
  2. Replies
    63
    Views
    7,385

    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...
  3. Replies
    63
    Views
    7,385

    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.
  4. Replies
    63
    Views
    7,385

    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...
  5. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    What good is that? There needs to be code that can be tested.
  6. Replies
    63
    Views
    7,385

    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...
  7. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Only add the listener once. It will be called for each time it is added.
  8. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Interesting? I've never seen that. Usually its 2 like the code posted earlier.
    Where are the statements that create those 4 instances?
    Is there a loop that creates the 4 new instances of the...
  9. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    The simple answer is to change the code so that it only opens one.
    How many are openned?
    Are all the new GUIs the same or are they all different?
    How many places does the code create a GUI? Why...
  10. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Good, now look at how the code in post#45 works and copy that technique to the other code.

    If there error messages, copy the full text and paste it here.
  11. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    That code isn't any good for testing. It needs to be complete.

    Did you miss post#40 about removing "frame."?
  12. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Post the new version of the code.
    I made the changes I've described and it works for me.
  13. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    How many lines of code did you remove? You were only supposed to remove ONE line:
    JFrame frame = new JFrame();

    That required that all usages of the variable: frame be changed to use the JFrame...
  14. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    This one:
    JFrame frame = new JFrame();

    and use the one that Game extends.
  15. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    There should only be one JFrame created. Get rid of one of them.
  16. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    The code creates two JFrames:

    new game();

    JFrame frame = new JFrame();

    and closes the game frame. The JFrame referred to by the frame variable is not closed.
  17. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Can you make a small, complete program that compiles, executes and shows the problem?

    Add a call to setVisible(false);
  18. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    What happened when you compiled and executed the code?
  19. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Are you saying you do not know how to call a method?

    You code must be full of calls to methods.
    For example these statements are calls to methods:

    dispose();

    ...
  20. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    That's a lot closer. I used a D not a d in the name. What you have will work, but it doesn't follow the naming conventions.
  21. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    What was the name of the method I suggested be added?
    What is the name of the method you added?
    Are they the same?
    That's your answer.
  22. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Take it one step at a time.
  23. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Another way:
    Add a method named: callDispose() to the Game class. Have that method call dispose().
    From the listener method in the inner class, call the callDispose() method.
  24. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    Where is the class with the dispose() method? You need a reference to the class's object to be able to call its dispose() method. The posted code does not show a class that has a dispose() method.
  25. Replies
    63
    Views
    7,385

    Re: dispose(); not working

    You need a reference to the object to be able to call its methods.

    The this keyword refers to the object that it is executing in. The example shown:
    this.dispose()
    doesn't do anything...
Results 1 to 25 of 25