Search code examples
javaslick2d

Importing java variables between classes


I have two classes. One class has a variable "Image plane = null;" in this class (Class1) I call a function move.lookright() which executes a function on another class file called move.java, My issue is I need to import a few variables into this class so that I can use them and make the Image move right when the function is called.

void lookRight() {
    if(plane.getRotation() < 0 ){       
        if(plane.getRotation()>-270 ){
            plane.rotate(-0.2f * delta);
        }
        if(plane.getRotation()<1){
            plane.rotate(0.2f * delta);
        }
    }
}

This class needs the variables delta and plane.

Any help is appreciated. And yes I did google this answer many times but was unable to find a answer.

Thanks, Kyle


Solution

  • Change the method signature to

    void lookRight(DataTypeOfPlane plane, double delta)
    // replace DataTypeOfPlane with the actual data type of the variable plane ;)
    

    and pass the parameters when calling the method.