Home > Default > Problem with JFrame's dispose();

Problem with JFrame's dispose();

October 11Hits:2
Advertisement
Hello everyone,
I'm having a problem with JFrame's dispose() method. In my program I have 2 classes which go into full screen. On each screen there is a button to switch to the other screen. The first time I push the button on both of them the other screen closes, which is what I want. However, if I push the same button more than twice - like by going from Screen1 to Screen2 and Screen2 to Screen1 and then Screen1 to Screen2 - I get 2 screens. If I keep doing that I eventually get 10+ screens up, which is bad. How do I prevent that?

Answers

There's a lot of code, so I'll just post up the part that does it.
backButton.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                  soundManagerM.close();
                    new MenuScreen().setVisible(true);
                    dispose();
         });I don't think it opens up 2 at once, because it would play multiple music right?

Read other 9 answers

Tags:

Related Articles

  • Problem with JFrame's dispose();October 11

    Hello everyone, I'm having a problem with JFrame's dispose() method. In my program I have 2 classes which go into full screen. On each screen there is a button to switch to the other screen. The first time I push the button on both of them the other

  • Problem with JFrame updatingOctober 11

    I'm having trouble making this application remove the "Client 1: 127.0.0.1 [localhost]" (and Client 2: or how ever many are connected) from a Box inside of a JPanel inside of a JFrame... I searched around a bit, but nothing fixed my problem. (Sw

  • Is there a problem with JFrame and window listeners?October 11

    As the subject implies, i'm having a problem with my JFrame window and the window listeners. I believe i have implemented it properly (i copied it from another class that works). Anyway, none of the events are caught and i'm not sure why. Here's the

  • How to know the child JFrame  is disposeNovember 30

    There are two JFrames, the first one is a parent, and the second is child and created by the parent. How to parent knows the child disposed. Because of the other member functions of parent shall be running while child is disposed.hi! do you know abou

  • Waiting for a JFrame to disposeNovember 30

    Hello, i have this situation: i have 2 JFrames, let's say JFrame1 and JFrame2. JFrame1 invokes and displays JFrame2, like this: /* JFrame1 code */ JFrame2 f2 = new JFrame2(); f2.setVisible(true); //wait f2 to dispose other code...My problem is how to

  • Problem with JFrame and busy/wait CursorOctober 11

    Hi -- I'm trying to set a JFrame's cursor to be the busy cursor, for the duration of some operation (usually just a few seconds). I can get it to work in some situations, but not others. Timing does seem to be an issue. There are thousands of posts o

  • Advance level drawing problem with Jframe and JPanel need optimize sol?October 11

    Dear Experts, I m trying to create a GUI for puzzle game following some kind of "game GUI template", but i have problems in that,so i tried to implement that in various ways after looking on internet and discussions about drawing gui in swing, b

  • Problem with JFrame and JPanelOctober 11

    Okay, well I'm busy doing a lodge management program for a project and I have programmed this JFrame import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FinalTest extends JFrame      public JPanel contentPane;      public J

  • Problem with JFrame , please help !October 11

    hello , all ! I define a JFrame1 as ancestor I set the JFrame's contentPane Layout to borderLayout , and add some component in south , north , and add a menu , in its constructor then I define a new JFrame2 inherit from JFrame1, I also add a Jpanel c

  • Problem with JFrame class.October 11

    To risolve my problem i need for few diferent frame ( for esample in one i put JTextFild that take the user input, in a nother one i need for program output ) . But, th problem is, all my frames using the same object. If i construct diferent JFrame w

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.631 s.