-3

有一个奇怪的,我有一个变量,t我在一个类中使用它,它发生了变化,(例如 1 变为 5)然后我从另一个类调用它以在该类中使用,问题是当它通过时 t 始终为 0,我究竟做错了什么

这是编辑它的班级中的 t

public int t = 1; //defualt value for amount of seconds in the future the job should wait untill sent

    public int getT() {
        return (t);
    }

    public void setT(int t) {
        this.t = t;
    }

这是我正在使用的类,它从上述类中调用 t 来使用:

public class DealyTillPrint {

    public int t;

    public String CompletefileName;
    private String printerindx;
    private static int s;
    private static int x;
    public static int SecondsTillRelase;

    public void countDown() {
        System.out.println("Countdown called");
        s = 1; // interval 
        t = (t * 60); // number of seconds
        System.out.println("t is : " + t);
        while (t > 0) {
            System.out.println("Printing in : " + t);
            try {
                Thread.sleep(s * 1000);
            } catch (Exception e) {
            }
            t--;
        }

这是我t使用微调器设置的地方

<p:spinner min="1" max="1000" value="#{printerSettings.t}"  size ="1">
                    <p:ajax update="NewTime"/>
                </p:spinner>

我如何在传递的值不为零的地方调用 t

4

2 回答 2

1

DealyTillPrint你声明public int t; 这与你在第一个代码示例中声明的t不同。t由于您没有给它任何值,因此分配了默认值 0。您t在第一个示例t中与第二个示例中没有任何分享。

更改t = (t * 60); // number of secondst = (printerSettings.getT() * 60);

于 2013-02-11T17:14:50.480 回答
0

您需要printerSettings从网页中获取对象到您的DealyTillPrint对象中。查看您提交的代码,我无法告诉您如何做到这一点。

于 2013-02-11T17:23:45.643 回答