变量不传入另一个类Java

时间:2013-02-11 17:09:42

标签: java

得到一个奇怪的,我有一个变量t我在一个类中使用它,它改变,(例如1变为5)然后我从另一个类调用它在该类中使用,问题是t当它通过时总是0,我做错了什么

这里是编辑它的类

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传递的非零值

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

您需要将网页中的printerSettings对象放入DealyTillPrint对象中。我无法告诉你如何查看你提交的代码。

相关问题