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 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 64

Thread: dispose(); not working

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    i updated the name.
    Last edited by newtolearningjava; April 26th, 2014 at 05:48 PM.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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();
     
         setVisible(false);
     
        transferControlToClass2();


    callDispose  dispose = new callDispose ();
    That's a call to a class's constructor. But there is no class named: callDispose. That is the name of a method.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    Am i on the right track here?
    Last edited by newtolearningjava; April 26th, 2014 at 05:49 PM.

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

    Am i on the right track here?
    What happened when you compiled and executed the code?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    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
    What happened when you compiled and executed the code?
    it opens the new gui but never closes the old one

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

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

    Add a call to setVisible(false);
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    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
    Can you make a small, complete program that compiles, executes and shows the problem?

    Add a call to setVisible(false);
    m that compiles, executes and shows the problem?
    m that compiles, executes and shows the problem?
    m that compiles, executes and shows the problem?
    Last edited by newtolearningjava; April 26th, 2014 at 05:49 PM.

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    in my original code i have so this why i have done it like this in the program. how do i fix it?

    I was told i have to use EXTEND JFrame
        public class game extends JFrame {
    Last edited by newtolearningjava; April 26th, 2014 at 05:49 PM.

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

    There should only be one JFrame created. Get rid of one of them.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    this is my original code when i get rid of frame nothing appears when it is complied
    D OF ??
    Last edited by newtolearningjava; April 26th, 2014 at 05:50 PM.

  13. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

    WHICH DO I GET RID OF ??
    This one:
    JFrame frame = new JFrame();

    and use the one that Game extends.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    BUT when i complie my code there is no gui it just says
    BUILD SUCCESSFUL (total time: 6 seconds)

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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 provided by the Game class. Basically just remove "frame."
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    so remove this line of code ????
    JFrame frame = new JFrame();

    if i do this there is error for cannot find symbol
    symbol: method add(JPanel,String)
    location: class Object
    ----
    Last edited by newtolearningjava; April 19th, 2014 at 07:08 PM.

  17. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

    Post the new version of the code.
    I made the changes I've described and it works for me.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    did u make changes in the code which is on post no37?[COLOR="Silver"]

    --- Update ---
    Last edited by newtolearningjava; April 26th, 2014 at 05:50 PM.

  19. #44
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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."?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    here is the mini program you told me to make it works

    IN MY ORIGINAL PROGRAM IT DOES NOT WORK WHICH IS WHAT IM TRYING TO GET WORKING
    Last edited by newtolearningjava; April 26th, 2014 at 05:50 PM.

  21. #46
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

    it works
    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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    yes i have it working BUT when i click the button to open the new gui it opens more than 1 so how i get rid of that?

  23. #48
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

    when i click the button to open the new gui it opens more than 1
    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 is more than one executed?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: dispose(); not working

    it opens
    Last edited by newtolearningjava; April 26th, 2014 at 05:51 PM.

  25. #50
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: dispose(); not working

    it opens 4 for the new gui, they are the same
    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 same class?

    --- Update ---

    How many times is the actionPerformed() method called? The code in it creates a new Game2 every time it is called.

    Add a println() method to the actionPerformed() method to see how many times it is called.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 3 FirstFirst 123 LastLast

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 27th, 2009, 12:03 AM