?
Solved

How to refresh Swing JTabs : JAVA, RMI, SWING

Posted on 2005-03-19
6
Medium Priority
?
1,247 Views
Last Modified: 2013-11-23
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

0
Comment
Question by:_Esam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Triguna
ID: 13589592
before adding elements to panel,

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

then panel.add(tab); and panel.setVisible(true);
0
 

Author Comment

by:_Esam
ID: 13599519
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
 
LVL 5

Expert Comment

by:Triguna
ID: 13600256
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:_Esam
ID: 13635536
 >>         //I thought it as a log on window.

I gave the code ...

_Esam
0
 
LVL 5

Expert Comment

by:Triguna
ID: 13635954
Have you seen my comment
0
 
LVL 5

Accepted Solution

by:
Triguna earned 400 total points
ID: 13635959
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question