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

Thread: need help with the code will not close window buts opens the right window

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    26
    My Mood
    Nerdy
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation need help with the code will not close window buts opens the right window

    @Override
        protected void processWindowEvent(WindowEvent e){
     
            if (e.getID() == WindowEvent.WINDOW_CLOSING) {
     
                int exit = JOptionPane.showConfirmDialog(this, "Are you sure? Your Game Will Not be Saved!");
                if ((exit == JOptionPane.YES_OPTION)) {
                Game_titleMenue s = new Game_titleMenue();
                s.setVisible(true);
                close();
                }   
            }
            else 
            {
                super.processWindowEvent(e);
            }
        }
     
        private void close() {
            WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
        }
     
    }

    trying to close the jframe that is open and open another jframe to go back to the program selection.
    but reopens the jframe that was open ect. try running the coed with 2 jframes and you will see my problem.
    Last edited by op117; August 27th, 2012 at 06:15 PM.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: need help with the code will not close window buts opens the right window

    I suggest that you consider changing your GUI structure as no user is going to enjoy using a GUI that opens, closes and throws windows at them willy-nilly. Think of most of the GUI programs that you use including word processors, games and browsers, and you'll see that most of them have one main window (the Java equivalent of a JFrame), that they occasionally show dialogs (the Swing equivalent of a JDialog or JOptionPane), and that they often swap *views* in the main window (the Swing equivalent of using a CardLayout).

    Instead I suggest you gear your GUI towards creating JPanel views which will give you the flexibility of placing these views inside of JFrames, JDialogs, other JPanels, or wherever you'd like. If you're not familiar with the CardLayout, I also suggest that you check out the tutorial as it is *very* handy to use.

    If on the other hand you absolutely need this current design and are still stuck, consider creating and posting a small compilable and runnable program that demonstrates your problem for us, an SSCCE.
    Last edited by curmudgeon; August 27th, 2012 at 08:12 PM.

  3. The Following User Says Thank You to curmudgeon For This Useful Post:

    op117 (August 28th, 2012)

  4. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    26
    My Mood
    Nerdy
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: need help with the code will not close window buts opens the right window

    will try the GUI resigned did not know a bout that. will look in to it thinks.

Similar Threads

  1. Replies: 1
    Last Post: December 17th, 2011, 03:32 AM
  2. JDK Fullscreen window
    By Nameo0 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 13th, 2011, 08:16 AM
  3. Craating non active window ,and inputing to the non active window.
    By java-beginner in forum Java Theory & Questions
    Replies: 0
    Last Post: February 25th, 2011, 10:13 PM
  4. cmd.exe DOS Window
    By Curious in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2010, 10:30 AM
  5. Navigating from one window to another
    By visharaddhavle83 in forum AWT / Java Swing
    Replies: 2
    Last Post: August 6th, 2009, 07:55 AM

Tags for this Thread