-2

I'm trying to set a logon frame using Java Swing - Eclipse.

I can't find how to redirect the user to another frame on success of the operation.

Any brilliant idea, please?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Lucie kulza
  • 1,357
  • 6
  • 20
  • 31
  • 1
    `Any brilliant idea, please?` yeah... what have you tried? – Frakcool May 26 '14 at 13:42
  • @Frakcool, I wasn't able to find a good documentation about that – Lucie kulza May 26 '14 at 13:44
  • 5
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) What this needs is either a `CardLayout` or (more likely) a modal `JDialog` or a `JOptionPane`. – Andrew Thompson May 26 '14 at 13:45
  • Luciekulza you can if you haven't read @AndrewThompson's suggestion about the use of multiple frames, and you still want to use them, then you can create a class with a main frame, then another class with another frame. Each one, with their own constructor and on the `ActionListener` call that constructor. In the constructor you may create the GUI. – Frakcool May 26 '14 at 13:55
  • use panels when you want to redirect remove the global panel from you container and add the new panel to the container wich represent the new frame ,use one frame and many panels – oussama.elhadri May 26 '14 at 13:58
  • 1
    @Jorge_B [those Objects aren't GC'able](http://stackoverflow.com/questions/6309407/remove-top-level-container-on-runtime), never returns used memory bact to JVM, wrong suggestion for `newbee and with giv'me codez` – mKorbel May 26 '14 at 13:59
  • @oussama.elhadri, your suggestion seems interesting. Would you please give a short example explaining that? – Lucie kulza May 26 '14 at 14:00
  • `use one frame and many panels` - if this is the suggestion you found interesting, I would also suggest you follow the tips given by @AndrewThompson. From my mediocre experience level, he seems to give a really good nudge in the right direction. – jumps4fun May 26 '14 at 14:38

2 Answers2

1

create a SessionClass

put a final field in the class ( better create some long and complex no taking user id as input and use as session id )

when instantiated , pass the user id as the value of the final field

instantiate the class with user id , when logging in and keep passing this session object in every frame

0

create a login panel class and another panel that will be used after redirection ,and a
frame class when you want to do redirection remove the login panel from the frame and add the panel that contains your User Interface.

LoginPanel extends JPanel{

         public LoginPanel(JFrame frame) {
            createLoginPanel();
         }
        public void verifyConnexion(JFrame frame) {
           if(isTrueRedirect()){
                 frame.getContentPane().removeAll();
                 frame.getContentPane().add(new redirectedPanel());
                 frame.pack();
          }
       }

    }

    public class MyFrame extends JFrame {

           public MyFrame(){
            Container contenu = getContentPane();
            contenu.add(new LoginPanel(this));
        }
    }
oussama.elhadri
  • 738
  • 3
  • 11
  • 27