Results 1 to 10 of 10
  1. #1
    suhaib1thariq is offline Member
    Join Date
    Jan 2009
    Posts
    5
    Rep Power
    0

    Angry linking 2 Jframes

    i have a situation ....i have to create 2 JFrame ...
    i need to have a button in one Jframe which opens another Frame...when i close anyone Jframe ,the another wont close...i am trying for this ...can u help me

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I recommend that you don't use 2 JFrames, that instead your main application window be a JFrame and that the second window be a JDialog (modal or not depending on your need). You can read up on how to create and manipulate these at the Sun Swing tutorials.

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    You can also use a single JFrame and create multiple JPanel's, each containing a particular view. You can then add and remove each panel from the JFrame, switching the one that is currently displayed.

  4. #4
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    you can set HIDE_ON_CLOSE(in JFrame 2) instead of EXIT_ON_CLOSE :)

  5. #5
    ratb0y is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default

    Or you can also set visible to false on the first jframe and visible true to the second one. Is like you are swicthing "on" the one frame and "off" the other one

    pseudocode:

    onButtonClick event
    {
    hide frame(setvisible to false)
    open the second frame (call the second frame)
    }

    you can add afterwords a window close event where u will add a system exit in it (in the event[if window close{system exit}]).
    Last edited by ratb0y; 02-11-2009 at 08:03 PM.

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    The problem with 2 JFrames is that you have two application windows. As long as they are not directly connected, that isn't terrible, but I would much rather have two tabs in one browser than two browsers. When it's an application switching between screens, then it's just annoying.

    I routinely use two monitors. If I moved the first JFrame from one monitor to the second, then the second JFrame would appear on the first monitor. That's the worst case, but I hope it makes the point. GUI's should be consistent, without unnecessary flashing off and on.

    On the flip side, there is seldom any reason to use two JFrame's. A JFrame and a JDialogue, for prompting purposes.

    Learn to use JPanel and to manipulate the content pane. Doing things "the right way" doesn't take any more effort, once you know how, and it produces much better results.

  7. #7
    Ciwan is offline Banned
    Join Date
    Dec 2008
    Location
    Earth
    Posts
    87
    Rep Power
    0

    Default

    Thanks Steve :) I won't use two JFrames either now :)

  8. #8
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    I found Swing very annoying at first, even though I have created hundreds of GUI's in the past. Compared to anything but C++ and Windows back in the '90's, I have not found anything so "low level". Nothing seems to work as it appears on the surface.

    However, once I figured out what the underlying design, I found Swing to be powerful and fairly easy to use. Keep at it, and avoid the temptation to take short cuts (if you have time, we all face deadlines), learn MVC and use it religiously, and I think you'll find that Swing actually is quite good.

  9. #9
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    well actually Steve11235 someplace right concerning to 2 browsers instead of 2 tabs ))) but if there is a real need of both JFrames you can make it. As an example I can point obfuscator Zelix Klass Master. Its GUI is just made of JFrames and still works fine ;)
    So you can choose many ways for your GUI style expression...

  10. #10
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    Webuser is right in saying that using 2 JFrames is not criminal or anything. Advanced applications often bring out a requirement to use an unusual approach.

    I'm talking in general, for simple applications...

Similar Threads

  1. two JFrames
    By kirtesh4u in forum New To Java
    Replies: 0
    Last Post: 11-17-2008, 09:26 PM
  2. Linking of exe files
    By archu2friends in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-06-2008, 07:08 AM
  3. <URGENT> problem after linking .jnlp
    By bongia in forum New To Java
    Replies: 14
    Last Post: 11-18-2007, 06:57 PM
  4. Linking code to GUI Interface
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-02-2007, 02:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •