Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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

如有任何疑问/问题,请随时发表评论