Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

JFrame filling / refreshing problem

Thread view: 
Lancelot dM - 28 Mar 2005 17:54 GMT
Hi i'm currently working on an application's GUI.
At the beginning i'm asking the user to enter a code.
If it's right i'm loading some sort of encrypted database.
This operation takes a few seconds and I would have liked to show a splash
screen while waiting. It would disappear at the end of the operation and
then the application interface shows up.
The problem is that my "splash" frame doesn't have any component displayed,
not even a label. I have noticed that in fact this screen fills in after
the main application has been displayed (at that time the splash screen is
hidden, to see that I had commented the "loadingFrame.setVisible(false)
line")

Here is the code (it's in english but the String displayed are in french) :

public class PsychologGUI extends JFrame{
   
   private final String filepaths="data/filepaths.xml";
   private final int applicationWidth=800;
   private final int applicationHeight=600;
   private final int buttonWidth=200;
   private final int buttonHeight=40;
   private int screenHeight;
   private int screenWidth;
   private Dimension displayPanelDimension;
   private String iconspath;
   
   
   //storage objects
   private int key;
   private Hashtable files;
   private UsersStorage usersStorage;
   private Storage storage;
   
   //GUI objects
   private javax.swing.JPanel buttonMenuPanel;
   private javax.swing.JButton createButton;
   private javax.swing.JPanel currentPanel;
   private javax.swing.JPanel displayPanel;
   private javax.swing.JButton helpButton;
   private javax.swing.JPanel mainPanel;
   private javax.swing.JPanel menuPanel;
   private javax.swing.JButton quitButton;
   private javax.swing.JButton loadButton;
   private javax.swing.JButton viewButton;
   
   /** Creates a new instance of PsychologGI */
   public PsychologGUI() {        
       //Sets the Windows' LookAndFeel
       String lnf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
       try {
           UIManager.setLookAndFeel(lnf);
           SwingUtilities.updateComponentTreeUI(this);
       } catch (UnsupportedLookAndFeelException ex1) {
           System.err.println("LookAndFeel non supporte : " + lnf);
       } catch (ClassNotFoundException ex2) {
           System.err.println("Classe de LookAndFeel non trouvee : " + lnf)
;
       } catch (InstantiationException ex3) {
           System.err.println("LookAndFeel ne peut etre charge : " + lnf);
       } catch (IllegalAccessException ex4) {
           System.err.println("LookAndFeel ne peut etre utilise : " + lnf);
       }
       
       //retrieves the dimension of the screen
       Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
       this.screenHeight=d.height;
       this.screenWidth=d.width;
       this.setLocation((this.screenWidth-this.applicationWidth)/2,
(this.screenHeight-this.applicationHeight)/2);
       this.setResizable(false);
       
       
       //loads the filepaths Hashtable
       try {
           files=new Hashtable();
           new XMLReader(files,this.filepaths);
       } catch (SAXException e){
           System.err.println("Error : invalid filepaths file");
           e.printStackTrace();
       } catch (javax.xml.parsers.ParserConfigurationException e){
           System.err.println("Error : error parsing filepaths file");
           e.printStackTrace();
       } catch (IOException e){
            JOptionPane.showMessageDialog(this,
                       "Fichier manquant, veuillez réinstaller le
logiciel",
                       "Erreur",
                       JOptionPane.ERROR_MESSAGE);
           System.err.println("Error : bad structure in filepaths file");
           e.printStackTrace();
       }
       this.iconspath=(String)this.files.get("iconspath");
       setIconImage(new ImageIcon(this.iconspath+"psycone32e.png")
.getImage());
       
       //asks decoding key
       JPanel keyPanel=new JPanel();
       keyPanel.add(new JLabel("Entrez la clé"));
       JPasswordField keyField =new JPasswordField();
       keyField.setColumns(10);
       keyPanel.add(keyField);
       Object[] options=new Object[2];
       options[1]="Annuler";
       options[0]="Valider";
       int n;
       boolean isNumber;
       boolean validKey=false;
       do {
           isNumber=false;
           do {
               n=JOptionPane.showOptionDialog(this,keyPanel,
                       "Idenfication",
                       JOptionPane.OK_CANCEL_OPTION,
                       JOptionPane.PLAIN_MESSAGE,
                       new ImageIcon(this.iconspath+"password.png"),
                       options,
                       options[0]);
               if (n==JOptionPane.OK_OPTION){
                   try{
                       this.key=Integer.parseInt(new String
(keyField.getPassword()));
                       isNumber=true;
                   }catch (NumberFormatException e){
                       JOptionPane.showMessageDialog(this,
                               "Clé incorrecte",
                               "Erreur",
                               JOptionPane.ERROR_MESSAGE);
                   }
               } else{
                   System.exit(0);
               }
           } while (!isNumber);
           
           
           //loads the usersdatabase
           this.usersStorage=new UsersStorage();
           try{
               new XMLReader(usersStorage,((String)this.files.get
("usersdb")),this.key);
               validKey=true;
           } catch (SAXException e){
               JOptionPane.showMessageDialog(this,
                       "Clé incorrecte",
                       "Erreur",
                       JOptionPane.ERROR_MESSAGE);
               System.err.println("Error : invalid users database file or
invalid key");
               e.printStackTrace();
           } catch (javax.xml.parsers.ParserConfigurationException e){
               System.err.println("Error : error parsing users database
file");
               e.printStackTrace();
           } catch (IOException e){
               JOptionPane.showMessageDialog(this,
                       "Erreur de lecture du fichier de base de données\
nVeuillez contacter le service après-vente ou réinstaller le logiciel",
                       "Erreur",
                       JOptionPane.ERROR_MESSAGE);
               System.err.println("Error : bad structure in users database
file");
               e.printStackTrace();
           }
       } while (!validKey);
       
       //Shows a loading window while loading the database
       // Probleme : le panneau ne se remplit qu apres avoir chargé la
base de données
     /*  JFrame loadingFrame=new JFrame();
       
       //loadingFrame.setIconImage(new ImageIcon
(this.iconspath+"psycone.png").getImage());
       
        JPanel loadingPanel=new JPanel();
       loadingPanel.setLayout(new BoxLayout(loadingPanel,BoxLayout.Y_AXIS))
;
       Dimension loadingDimension=new Dimension(400,300);
       loadingPanel.setPreferredSize(loadingDimension);
       loadingPanel.setMaximumSize(loadingDimension);
       loadingPanel.setMinimumSize(loadingDimension);
       JLabel image=new JLabel();
       image.setIcon(new ImageIcon(this.iconspath+"psycolog.png"));
       loadingPanel.add(image);
       JLabel bePatient=new JLabel("Veuillez patientez quelques
instants...");
       loadingPanel.add(bePatient);      
       loadingFrame.getContentPane().add(loadingPanel);
       loadingFrame.setResizable(false);
       loadingFrame.setUndecorated(true);
       loadingFrame.setLocation((this.screenWidth-400)/2,
(this.screenHeight-300)/2);
       loadingFrame.setDefaultCloseOperation
(WindowConstants.DO_NOTHING_ON_CLOSE);
       
       //loadingFrame.getContentPane().setLayout(new FlowLayout());
       //loadingFrame.getContentPane().add(new JLabel("toto")
,java.awt.BorderLayout.CENTER);
       loadingFrame.setUndecorated(true);
       loadingFrame.pack();
       loadingFrame.setVisible(true);
       loadingFrame.setVisible(true);
       loadingFrame.setVisible(true);*/
           
       
       
       //loads the tests database (it can take a while)
       this.storage=new Storage();
       try{
           new XMLReader(this.storage,((String)this.files.get("db")),key);
       }  catch (SAXException e){
           System.err.println("Error :invalid tests storage file");
           e.printStackTrace();
       } catch (javax.xml.parsers.ParserConfigurationException e){
           System.err.println("Error : error parsing tests storage file");
           e.printStackTrace();
       } catch (IOException e){
           System.err.println("Error : bad structure in tests storage
file");
           e.printStackTrace();
       }
       
       //loadingFrame.setVisible(false);  
   
       initComponents();
   }
David - 30 Mar 2005 15:46 GMT
En/na Lancelot dM via JavaKB.com ha escrit:
> Hi i'm currently working on an application's GUI.
> At the beginning i'm asking the user to enter a code.
[quoted text clipped - 220 lines]
>         initComponents();
>     }

I'm interested on this problem too. If you have/find an answer for this
question, please, post it.

Perhaps the solution can be using a SwingWorker class, but I don't see how.

Regards.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.