Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Jframe freezes while doing other task

  1. #1
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Jframe freezes while doing other task

    My Jframe uses apache libraries to login into a website, but the problem is that as soon as I click the button "Login" it freezes until it gets a response from the server, and that's not really cool...

    The Jframe has a username and a password field, and the button, when the ubtton is clicked it calls the login method that takes the info in those fileds and sends then to the website...

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: Jframe freezes while doing other task

    That's because you're tying up the EDT, which handles things like painting and firing events. You might consider doing the logging in on a separate thread or a SwingWorker.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Jframe freezes while doing other task

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Re: Jframe freezes while doing other task

    So how can I do that you are saying, do you have any referential links?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Jframe freezes while doing other task

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Re: Jframe freezes while doing other task

    Thank you a lot, I'll check that out and if I have another problem I'll post it here.

  7. #7
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Re: Jframe freezes while doing other task

    I'm too noob with java :'(....

    I have this two classes (Ill just put the important stuff)

    This class is the autentication window

    PHP Code:
    public class VentanaAutenticacion extends JFrame  {
        
    
        public VentanaAutenticacion() {
    
            initComponents();
            
        }
        
    
        private VentanaAutenticacion obtenerClase() { 
            return this; 
        }
        
        private void clickbotoningresar(java.awt.event.MouseEvent evt) {     
           
            //Verifies that fields are not empty
            VerificacionFormatoDatos formatodedatos = new VerificacionFormatoDatos(obtenerClase());
            
            //CLASS OF THE PROCESS I NEED TO EXECUTE ON BACKGROUND, THIS ONE FREEZES THE APP
            ProcesoAutenticacion procesoautenticacion = new ProcesoAutenticacion (obtenerClase());                
            
                 
            if(formatodedatos.analizar()==false){
            
                 JOptionPane.showMessageDialog (null, "Llene todos los campos.", "Información", JOptionPane.WARNING_MESSAGE);
               
            }
            
            else{            
                           
                            
                try{                
                    
                        //Here is where it freezes, it access proceso in the second class but until it gets the true or false value it just freezes
                        if(procesoautenticacion.proceso() == true){
                     
                        this.dispose(); 
                        VentanaChat chat = new VentanaChat ();
                        chat.label_nombredeusuario.setText(campo_usuario.getText()); 
                        chat.setVisible(true);
                    
                    }
                    else{                     
                         
                        JOptionPane.showMessageDialog (null, "Usuario o contraseña incorrectos.", "Error de autenticación", JOptionPane.ERROR_MESSAGE);
                    }
                    
                    }catch(Exception e){}           
            
            }
            
            
        }                                   
     
        
    }
    This class is the autentication process, called by the window

    PHP Code:
    public class ProcesoAutenticacion {     
        
        public VentanaAutenticacion autenticacion; 
      
        private String direccionweb="http://popre.net/forum/ucp.php?mode=login";    
            
         
        public ProcesoAutenticacion(VentanaAutenticacion autenticacion) {         
            
            this.autenticacion = autenticacion;         
            
        } 
      
        public boolean proceso() throws Exception {       
        
    
         
            DefaultHttpClient clientehttp = new DefaultHttpClient();
    
            HttpGet accederWeb = new HttpGet(direccionweb);
            
            HttpResponse respuestaservidor = clientehttp.execute(accederWeb);
            
            HttpEntity contenido = respuestaservidor.getEntity();      
            
            String codigo = EntityUtils.toString(contenido);                 
            
            List<Cookie> cookies = clientehttp.getCookieStore().getCookies();
    
            cookies = clientehttp.getCookieStore().getCookies();
    
            HttpPost enviarcontenido = new HttpPost(direccionweb); 
    
            camposWeb.add(new BasicNameValuePair("username", autenticacion.campo_usuario.getText()));
            camposWeb.add(new BasicNameValuePair("password", autenticacion.campo_clave.getText()));
            camposWeb.add(new BasicNameValuePair("login", "login"));
    
          
            enviarcontenido.setEntity(new UrlEncodedFormEntity(camposWeb, HTTP.UTF_8));
    
            respuestaservidor = clientehttp.execute(enviarcontenido);
    
            contenido = respuestaservidor.getEntity();
    
            codigo = EntityUtils.toString(contenido);                 
            
            cookies = clientehttp.getCookieStore().getCookies();
    
            clientehttp.getConnectionManager().shutdown();
    
    
                if(!codigo.contains(autenticacion.campo_usuario.getText())){ 
    
                    return false;  
    
                     }
    
                     else{ 
    
                     return true;   
                 }
                
        
        }
    
        
    }

    What am I supposed to do here? I tried doInBackground but didn't really seem to be doing it correctly...
    Last edited by danoc93; 05-12-2012 at 10:18 AM.

  8. #8
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Re: Jframe freezes while doing other task

    I haven't really advanced that much in this, can anobody tip me ;) BUMP BUMP

  9. #9
    danoc93 is offline Member
    Join Date
    Apr 2012
    Posts
    37
    Rep Power
    0

    Default Re: Jframe freezes while doing other task

    It turned out to be really easy... I just had to add a Runnable runnable = new Runnable(blahblahblah)}; with the process and then create a new thread(runnable).start();

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Jframe freezes while doing other task

    Just make sure that all updates to Swing components are performed on the EDT, as explained in the tutorial. If you neglect this, you'll run into intermittent problems that are difficult to debug.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. java sql update freezes
    By L19htn1n9 in forum Advanced Java
    Replies: 5
    Last Post: 05-06-2012, 02:15 AM
  2. JFrame freezes when button is clicked
    By JG4m3r in forum AWT / Swing
    Replies: 4
    Last Post: 04-06-2012, 03:20 AM
  3. JFrame freezes when button is clicked
    By JG4m3r in forum New To Java
    Replies: 2
    Last Post: 04-04-2012, 11:43 PM
  4. Server Socket GUI Freezes
    By mrhid6 in forum Threads and Synchronization
    Replies: 12
    Last Post: 09-30-2011, 04:39 PM
  5. Java Freezes in Control Panel
    By valpal1919 in forum New To Java
    Replies: 1
    Last Post: 04-19-2011, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •