How to refresh Swing JTabs : JAVA, RMI, SWING

Hi,
I have a client side Swing JTabs.
Once the user is verified in the logOn tab, the other two tabs are created, the makeRemainingTabs() method.

Problem is: If another user tries to log on, the other tabs are recreated with the old user id.
This probably is due to how I made the logic:

In logOn  ()

if ( userVerified == true) {
   makeRemainingTabs();
}


So, once a user is verified and logs in, other tabs are shown.
Now, if another user tried to log on, other tabs are recreated with an old id.

I would like other tabs to be non-visible, if another user tries to log in, i.e. clicks on the log on tab.

Not sure exactly how to do that..

Let me know..

Here is the complete code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.lang.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;


public class CoursePlannerV1 extends JFrame{
      private JTabbedPane tabbedPane;
    private static myRMIInterface myServerObject = null;
    private boolean isVerified;
    private int id = 0;
    private String password = null;
    private JTextField idField;
    private JPasswordField passwordField;
    private boolean userVerified;

    public CoursePlannerV1(myRMIInterface server){
            myServerObject = server;}


        private void logOn() {
    try {
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          tabbedPane = new JTabbedPane();

            JPanel logonPanel = new JPanel();

            logonPanel.setLayout( null );

            JLabel label1 = new JLabel( "UST ID:" );
            label1.setBounds( 10, 15, 150, 20 );
            logonPanel.add( label1 );

            //TextField
            idField = new JTextField();
            idField.setBounds( 10, 35, 150, 20 );
            logonPanel.add( idField );

            JLabel label2 = new JLabel( "Password:" );
            label2.setBounds( 10, 60, 150, 20 );
            logonPanel.add( label2 );

            //JPasswordField
            passwordField = new JPasswordField();
            passwordField.setBounds( 10, 80, 150, 20 );
            logonPanel.add( passwordField );

            JButton submitButton = new JButton("Log On");
            submitButton.setBounds(80, 120, 80, 20);
            logonPanel.add(submitButton);

            submitButton.addActionListener (new ActionListener(){
                        public void actionPerformed(ActionEvent event)
                                      {



///////////***********************i get the id from this idField
                                            try{
                                            id = Integer.parseInt(idField.getText());
                                            final String password = new String (passwordField.getPassword());
                                            System.out.println("ID = " + id);

                                                  try
                                                {
                                                    //verify user with a remote verification method
                                                      boolean userVerified = myServerObject.verify(id, password);
                                          System.out.println("Verification is " + userVerified); //print to see if verification is true
///////if verified, make other tabs.
                                                      if (userVerified == true) {
                                                            makeRemainingTabs();
                                                      }

                                              }
                                                catch(Exception e)
                                              {
                                              System.out.println("Exception occured: " + e);
                                                System.exit(0);
                                                }
                                          }

                                            catch(Exception e){
                                          e.printStackTrace();

                                          }
                                    }
                              }
                              );


            tabbedPane.addTab("Log On", logonPanel);
            getContentPane().add(tabbedPane);




      }

      catch (Exception e) {
            e.printStackTrace();
      }
        }//end of logOn

///////////////////i make the other tabs using the idField value from logOn()

   private void makeRemainingTabs(){

            try{
                  tabbedPane.addTab("View Courses", new JScrollPane(new JTable(new MyTableModel(myServerObject.getCoursesTaken(Integer.parseInt(idField.getText()))))));
          }
          catch (Exception e){
                  e.printStackTrace();
          }


          try{
                  tabbedPane.addTab("View Requirements", new JScrollPane(new JTable(new MyTableModel(myServerObject.getRequiredCourses(Integer.parseInt(idField.getText()))))));
             }
             catch (Exception e){
                  e.printStackTrace();
            }

     }





      public static void main(String[] argv){
            System.setSecurityManager(new RMISecurityManager());
                  if (argv.length != 1)
                    {
                        System.out.println("usage: java myRMIClient <IP address of host running RMI server>");
                      System.exit(0);
                  }
              String serverName = argv[0];
                  try
                        {
                            //bind server object to object in client
                          myServerObject = (myRMIInterface) Naming.lookup("rmi://"+serverName+"/myRMIImplInstance");
                              }
                  catch(Exception e)
                      {
                          System.out.println("Exception occured: " + e);
                          System.exit(0);
                      }

          System.out.println("RMI connection successful");

          CoursePlannerV1 cpv1 = new CoursePlannerV1(myServerObject);

          cpv1.logOn();
          cpv1.setSize(500, 300);
          cpv1.setVisible(true);
    }
}











Thanks.

_Esam

_EsamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TrigunaCommented:
before adding elements to panel,

do this, panel.removeAllElements() and panel.setVisible(false);

then panel.add(tab); and panel.setVisible(true);
0
_EsamAuthor Commented:
I am not sure if I understand...
I am adding the tabs in the container..not the panels ,,, right?

I pretty much showed the code above....

Could you please indicate how i can rearrange the code to reflect your suggestion?

Thanks.
_Esam

0
TrigunaCommented:
tabbedPane.addChangeListener(new ChangeListener(){

   public void stateChanged(ChangeEvent ce){
    if(tabbedPane.selectedIndex==0)
    {
           //I thought it as a log on window.
           new LogOn();
    }
    }
});

add the above code, after adding the tab to the frame.

After this,

create a class named,

public class LogOn extends JWindow
{
        public LogOn()
        {
              //Add your tools here

             //On Close, make setVisible(false);

              setBounds(100,200,300,400);
              setVisible(true);
        }
}
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

_EsamAuthor Commented:
 >>         //I thought it as a log on window.

I gave the code ...

_Esam
0
TrigunaCommented:
Have you seen my comment
0
TrigunaCommented:
tabbedPane.addChangeListener(new ChangeListener(){

   public void stateChanged(ChangeEvent ce){
    if(tabbedPane.selectedIndex==0)
    {
           //This is your login window.
           new LogOn();
    }
    }
});

add the above code, after adding the tab to the frame.

After this,

create a class named,

public class LogOn extends JWindow
{
        public LogOn()
        {
              //Add your tools here

             //On Close, make setVisible(false);

              setBounds(100,200,300,400);
              setVisible(true);
        }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.