2

I am creating a program that has a switch user feature, so basically I have two frames, log in frame and the main frame. The problem is, after I log in using the switch user feature the second time, my main frame gets so messy.

enter image description here

enter image description here

Here's my code for log in frame

if(e.getActionCommand().equals("Log In")){
        try {
            rs.absolute(0);
            while(rs.next()){
                if(rs.getString("Username").equals(login.usert.getText()) && rs.getString("Password").equals(login.passt.getText())){
                    rs = st.executeQuery("select * from employee where Email ='"+login.usert.getText()+"'");
                    while(rs.next()){
                        if(rs.getString("Email").equals(login.usert.getText())){
                            eid = rs.getInt("EID");
                            new gui().user.setText("User" + rs.getString("Nickname"));
                            login.frame.dispose();
                            break;
                        }   
                    }
                }
                else{

                    login.error.setText("Invalid username/password");
                }

            }

        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }

Here's my code for switch user button

ubutton.addActionListener(new ActionListener(){

        public void actionPerformed(ActionEvent e) {
            mainFrame.dispose();
            login.frame.setVisible(true);
        }
    });

thanks in advance!

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
iamLinker
  • 88
  • 1
  • 10
  • [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice) and [How to Use CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) for a possible solution – MadProgrammer Mar 24 '16 at 09:36
  • It's difficult to be sure, but given all the "transparency" you could have a painting issue related to; not calling `super.paintX` when overriding paint methods; using alpha based colors for the background instead of `setOpaque`; some other thing which isn't diagnosable from the out of context code snippet you've provided – MadProgrammer Mar 24 '16 at 09:38
  • Does your program start with the login or the main frame? Where is the code that actually creates the main frame? What is the gui class and how does `new gui().user.setText("User" + rs.getString("Nickname"));` do anything that has a lasting effect or is even shown to the user? – Mark Mar 24 '16 at 09:40
  • all panels are set to setOpaque(false), new gui is a class that holds the main frame. my program starts with the log in frame..sorry I am having triuble editing my post so I just answered your questions here... Ill also read the link you've provided. As always, thank you – iamLinker Mar 24 '16 at 10:04

0 Answers0