Java 如何在getArrow()本地更改if(ab)中x和y的值 公共类箭头{ 受保护的静态int x; 保护静电干扰; 公共无效集a(布尔值a){ 这个a=a; } 公共空立根(布尔b){ 这个.b=b; } 公共无效集合ab(布尔值ab){ this.ab=ab; } 公共箭头(int x1,int y1){ 这是x=x1; 这是y=y1; } 公共双getySpeed(){ 返回(-y速度*时间+时间*时间/10); } 公共布尔getX(){ return x+Math.abs(xSpeed*Time)
您面临问题的原因是您已将Java 如何在getArrow()本地更改if(ab)中x和y的值 公共类箭头{ 受保护的静态int x; 保护静电干扰; 公共无效集a(布尔值a){ 这个a=a; } 公共空立根(布尔b){ 这个.b=b; } 公共无效集合ab(布尔值ab){ this.ab=ab; } 公共箭头(int x1,int y1){ 这是x=x1; 这是y=y1; } 公共双getySpeed(){ 返回(-y速度*时间+时间*时间/10); } 公共布尔getX(){ return x+Math.abs(xSpeed*Time),java,class,int,Java,Class,Int,您面临问题的原因是您已将x和y声明为static使它们成为类变量,这意味着它们的值对于所有对象都是相同的 public class Arrow { protected static int x; protected static int y; public void setA(boolean a) { this.a = a; } public void setB(boolean b) { this.b = b; } public void setAb(boolean a
x
和y
声明为static
使它们成为类变量,这意味着它们的值对于所有对象都是相同的
public class Arrow {
protected static int x;
protected static int y;
public void setA(boolean a) {
this.a = a;
}
public void setB(boolean b) {
this.b = b;
}
public void setAb(boolean ab) {
this.ab = ab;
}
public Arrow( int x1, int y1) {
this.x=x1;
this.y=y1;
}
public double getySpeed(){
return (-ySpeed*Time+Time*Time/10);
}
public boolean getX(){
return x +Math.abs(xSpeed * Time)<canvasWidth-90;
}
public boolean getY(){
return y+getySpeed()<canvasHeight-110;
}
public Matrix getArrow(){
Matrix matrix = new Matrix();//1140,540
matrix.postRotate((int)getAngle(), arrowWidth/2, arrowHeight / 2);
if (a&&!ab) {
// here if i do sout(x) it will show 75 which is the value i gave it in the constructor
return a(x);
}
if(b&&!ab){
// here if i do sout(y) it will show 125 which is the value i gave it in the constructor
return (b(y));
}
if(ab){
x =x+(int) Math.abs(xSpeed * Time);
y = y+(int)getySpeed();
matrix.postTranslate(x,y );
}
return matrix;
}
public Matrix b(int yy ){
Matrix matrix = new Matrix();
matrix.postRotate((int)getAngle(), arrowWidth/2, arrowHeight / 2);
matrix.postTranslate(canvasWidth-90,yy );
return matrix;
}
public Matrix a(int xx ){
Matrix matrix = new Matrix();
matrix.postRotate((int)getAngle(), arrowWidth/2, arrowHeight / 2);
matrix.postTranslate(xx,canvasHeight-100 );
return matrix;
}
只需从他们的声明中删除术语,static
如果有任何疑问/问题,请随时发表评论。您面临问题的原因是您已将
x
和y
声明为静态
使它们成为类变量,这意味着它们的值对于所有对象都是相同的
public class Arrow {
protected static int x;
protected static int y;
public void setA(boolean a) {
this.a = a;
}
public void setB(boolean b) {
this.b = b;
}
public void setAb(boolean ab) {
this.ab = ab;
}
public Arrow( int x1, int y1) {
this.x=x1;
this.y=y1;
}
public double getySpeed(){
return (-ySpeed*Time+Time*Time/10);
}
public boolean getX(){
return x +Math.abs(xSpeed * Time)<canvasWidth-90;
}
public boolean getY(){
return y+getySpeed()<canvasHeight-110;
}
public Matrix getArrow(){
Matrix matrix = new Matrix();//1140,540
matrix.postRotate((int)getAngle(), arrowWidth/2, arrowHeight / 2);
if (a&&!ab) {
// here if i do sout(x) it will show 75 which is the value i gave it in the constructor
return a(x);
}
if(b&&!ab){
// here if i do sout(y) it will show 125 which is the value i gave it in the constructor
return (b(y));
}
if(ab){
x =x+(int) Math.abs(xSpeed * Time);
y = y+(int)getySpeed();
matrix.postTranslate(x,y );
}
return matrix;
}
public Matrix b(int yy ){
Matrix matrix = new Matrix();
matrix.postRotate((int)getAngle(), arrowWidth/2, arrowHeight / 2);
matrix.postTranslate(canvasWidth-90,yy );
return matrix;
}
public Matrix a(int xx ){
Matrix matrix = new Matrix();
matrix.postRotate((int)getAngle(), arrowWidth/2, arrowHeight / 2);
matrix.postTranslate(xx,canvasHeight-100 );
return matrix;
}
只需从他们的声明中删除术语,static
如有任何疑问/问题,请随时发表评论