简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM