Java 为什么drawString不更新值?

Java 为什么drawString不更新值?,java,draw,paintcomponent,Java,Draw,Paintcomponent,我在画这个(用画法): 要输出以下方法中定义的值: public void addPipe() { for (int i = 0; i < pipe.length; i++) { if (pipe[i] == null) { pipe[i] = new Pipe(this.width, (int) Math.random() * (this.height - 200)); System.out.println("Pip

我在画这个(用画法):

要输出以下方法中定义的值:

public void addPipe() {
    for (int i = 0; i < pipe.length; i++) {
        if (pipe[i] == null) {
            pipe[i] = new Pipe(this.width, (int) Math.random() * (this.height - 200));
            System.out.println("Pipe Added.");
            numPipes += 1;
        }
    }
}

public void deletePipe() {
    for (int i = 0; i < pipe.length; i++) {
        if (pipe[i] != null && pipe[i].returnX() <= 0) {
            pipe[i] = null;
            System.out.println("Pipe Deleted.");
            deletedPipes += 1;
        }
    }
}

public void movePipe(int speed) {
    for (int i = 0; i < pipe.length; i++) {
        if (pipe[i] != null) {
            pipe[i].move(speed);
            numMoved = numMoved + 1;
            System.out.println(numMoved);
        }
    }
}
public void addPipe(){
对于(int i=0;i如果(pipe[i]!=null&&pipe[i].returnX()您似乎没有调用
repaint
,因此该组件不知道它应该更新值

例如

public void addPipe() {
    for (int i = 0; i < pipe.length; i++) {
        if (pipe[i] == null) {
            pipe[i] = new Pipe(this.width, (int) Math.random() * (this.height - 200));
            System.out.println("Pipe Added.");
            numPipes += 1;
        }
    }
    repaint();
}
public void addPipe(){
对于(int i=0;i
现在,您可以将
repait
放在
numPipes+=1
之后,但由于
repait
的工作方式,可能不会有什么不同


这假设
addPipe
所属的类是某种组件,但您没有提供足够的信息来进行正确的诊断…

omg…是的,谢谢。由于语法/简单错误,我可能现在就结束这个问题。不过,谢谢。我一直都在这样做:p
public void addPipe() {
    for (int i = 0; i < pipe.length; i++) {
        if (pipe[i] == null) {
            pipe[i] = new Pipe(this.width, (int) Math.random() * (this.height - 200));
            System.out.println("Pipe Added.");
            numPipes += 1;
        }
    }
    repaint();
}