Use return in java

1

I have the following method:

public Object loginUser () {
    String soapEndpointUrl = "http://gamificacioc.com:80/ServerGIOC/webservices";
    String soapAction = "http://gamificacioc.com:80/ServerGIOC/comprovarLogin";

    //Recollim les dades dels buttons e inicialitzem variables
    String usuari = txtUsuari2.getText(); 
    String usuariContrasenya = textPassword2.getText();

   WebServiceCalls calls = new WebServiceCalls();
   Object authId = null;

    //Exemple sense recollir la info dels  butons ho tinc per probar directament sense recollir dels buttons
   // System.out.println(calls.comprovarLogin("fbarcia", "password"));

   //Recollin't la info dels buttons.
    SoapObject resposta = calls.comprovarLogin(usuari, usuariContrasenya);
     if (resposta == null)
     {
         JOptionPane.showMessageDialog(null, "Error falten dades");
     }

     else
     {
         //Si els buttons son plens verifica que sigui correcte
        authId= resposta.getPrimitiveProperty("authId");
        //authId ens dona el resultat que volem pasar per saber el tipus User

     //Enviem l'authId per poder saber que usuari es...         
     String resposta2 = calls.tipusUsuari(authId.toString()); 
     System.out.println(authId);


     //USUARIS D'EXEMPLE:
     //fbarcia password com admin
     //xingles 123456 com profe
     //mmaqueda contra com a alumne

     if(resposta2.equalsIgnoreCase("Admin")) {
        //Obrim pantalla administrador      
        pantalla_administrador v2 = new pantalla_administrador();
        v2.setVisible(true); // La fem visible
        dispose(); // així tanquem la finestra       



     }
     else if(resposta2.equalsIgnoreCase("profe")) {
        //Obrim pantalla professor          
        pantalla_Professor v2 = new pantalla_Professor();
        v2.setVisible(true); // La fem visible
        dispose(); // així tanquem la finestra

     }

     else if(resposta2.equalsIgnoreCase("pare") || resposta2.equalsIgnoreCase("alumne")) {

          JOptionPane.showMessageDialog(null, "Aquest tipus d'usuari no pot iniciar sessió aquí."); 
          //Esborrem les dades
          txtUsuari2.setText(""); 
          textPassword2.setText(""); 
     }
     else {

          JOptionPane.showMessageDialog(null, "No existeix aquest usuari."); 
          //Esborrem les dades  
          txtUsuari2.setText(""); 
          textPassword2.setText(""); 
     }   
     }
    return authId;

}

I need to use the authId in another class ..

that is, the result of that method.

How can I do it?

Do I have to make a call something like that?

ClaseX xxxx = new ClaseX();

And what next?

xxxx. ???

Thanks!

    
asked by Montse Mkd 21.11.2018 в 22:17
source

1 answer

2

This would be the correct way, assuming your class is called Clase :

   public class Clase{

        public Object loginUser () {
         ....
         return ...
        }

    }

first instance the class:

Clase clase = new Clase();

and later you can call the method which returns a value type Object :

Object myObject = clase.loginUser();
    
answered by 21.11.2018 / 22:26
source