java计时器将无法正常工作

时间:2014-11-04 19:27:12

标签: java swing timer

我尝试将类中定义的int设置为0,5秒后将其更改为0以上。任何帮助都将非常感谢!

我有一个程序,用户必须输入分数。

private void inputResponse(int pNum) {
    Patient p = null;
    p = patientList.get(pNum);
    Map<String, List<Double>> pData = sEWSTracker.get(p);
    List<Double> sEp = pData.get("SEW");
    Double sEWS = sEp.get(sEp.size() - 1);

    Component frame = null;

    Object[] response = {"Alert", "Verbal", "Pain", "Unresponsive"};
    String r = (String) JOptionPane.showInputDialog(
            frame,
            "Please input the patient’s response external stimulus:\n", "Please Report Patient's Response Level",
            JOptionPane.PLAIN_MESSAGE, null,
            response, response[0]);

    int reACT = 0;

    if (r.equals("Verbal")) {

        if (pNum == 0) {
            p0checked = 1;
        }
        if (pNum == 1) {
            p1checked = 1;
        }
        if (pNum == 2) {
            p2checked = 1;
        }
        if (pNum == 3) {
            p3checked = 1;
        }
        if (pNum == 4) {
            p4checked = 1;
        }
        if (pNum == 4) {
            p5checked = 1;
        }

    }
    if (r.equals("Pain")) {

        if (pNum == 0) {
            p0checked = 2;
        }
        if (pNum == 1) {
            p1checked = 2;
        }
        if (pNum == 2) {
            p2checked = 2;
        }
        if (pNum == 3) {
            p3checked = 2;
        }
        if (pNum == 4) {
            p4checked = 2;
        }
        if (pNum == 4) {
            p5checked = 2;
        }

    }
    if (r.equals("Unresponsive")) {

        if (pNum == 0) {
            p0checked = 3;
        }
        if (pNum == 1) {
            p1checked = 3;
        }
        if (pNum == 2) {
            p2checked = 3;
        }
        if (pNum == 3) {
            p3checked = 3;
        }
        if (pNum == 4) {
            p4checked = 3;
        }
        if (pNum == 4) {
            p5checked = 3;
        }

    }

    Double sEWP = (reACT * 1.0) + sEWS;
    List<Double> soEWS = pData.get("SEW");
    soEWS.add(sEWP);

    this.repaint();
    sEWSreact(pNum);

}

在他们这样做之前,代表处上面有一条消息说&#34; Partial Score&#34;:

(例如)

if (p0checked == 0) {

    g2.setColor(darkOrange);
    g2.fillRoundRect(250, 152, 120, 35, 10, 10);
    g2.setColor(mellowOrange);
    g2.fillRoundRect(252, 154, 116, 31, 10, 10);
    g2.setColor(darkBlue);
    g2.setFont(helvetica1);
    g2.drawString("Partial", 272, 170);
    g2.setFont(verdanda4);
    g2.setColor(Color.white);
    g2.drawString("Click here to update", 258, 182);
}
}

然后是一个计时器,将额外的分数重置为0,以便使部分分数通知返回并且分数返回到原始分数。 ......然而,没有任何反应

if (p0checked > 0) {
    Timer tim = new Timer(5 * 1000, new ActionListener() {@Override
        public void actionPerformed(ActionEvent e) {
            if (timSec >= 1) {
                p0checked = 0;
            }
            timSec++;
        }
    });
    tim.start();
}

timSec在类中定义为(为0)。

0 个答案:

没有答案