[英]Importing java variables between classes
I have two classes. 我有两节课。 One class has a variable "Image plane = null;"
一类具有变量“图像平面= 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.
在这个类(Class1)中,我调用一个函数move.lookright(),该函数在另一个名为move.java的类文件上执行一个函数,我的问题是我需要将一些变量导入该类中,以便可以使用它们并使调用函数时图像向右移动。
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. 此类需要变量delta和plane。
Any help is appreciated. 任何帮助表示赞赏。 And yes I did google this answer many times but was unable to find a answer.
是的,我已经多次在Google上搜索过此答案,但找不到答案。
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. 并在调用方法时传递参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.