문제

import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;


public class Boggle {
    Board board;
    Player player;
    Timer timer;
    boolean active;

    static Scanner in = new Scanner(System.in);

    public Boggle() {
        board = new Board(4);
        timer = new Timer();
    }

    public void newGame() {
        System.out.println("Please enter your name: ");
        String line = in.nextLine(); 
        player = new Player(line);
        active = true;

        board.shuffle();
        System.out.println(board);

        timer.schedule(new timesUP(), 20000);
        while(active) {
            String temp = in.nextLine();
            player.addGuess(temp);
        }
    }


    public void endGame() {
        active = false;
        int score = Scoring.calculate(player, board);
        System.out.println(score);
    }


    class timesUP extends TimerTask {
        public void run() {
            endGame();
        }
    }


    public static void main(String[] args) {
            Boggle boggle = new Boggle();
            boggle.newGame();

    }
}

I have the above class which should perform a loop for a given length of time and afterwards invoke an instance method. Essentially I need the loop in newGame() to run for a minute or so before endGame() is invoked on the current instance. However, using the Timer class I'm not sure how I would invoke the method I need on the current instance since I can't pass any parameters to the timertasks run method?

Is there an easy way to do this or am I going about this the wrong way? (note: this is a console project only, no GUI)

==========

code edited

I've changed the code to the above following the recommendations, and it works almost as I expect however the thread still doesnt seem to end properly. I was the while loop would die and control would eventually come back to the main method. Any ideas?

도움이 되었습니까?

해결책

웹 응용 프로그램에 URL을 입력 할 수있는 링크를 사용하면 URL을 입력 할 수 있으므로 URL을 입력하지 않으면 Web Application Scope입니다.

하위 레벨 (사이트 모음, 웹, 목록 등)에서 제어하는 것은 명령으로 불가능합니다.단일 목록 에서이 작업을 수행하려면 XSL을 사용할 수 있습니다.

stsadm 명령 stsadm -o setproperty -pn days-to-show-new-icon -pv 14는 2010 년에도 유효합니다.

다른 팁

"nofollow"> .val() 아닌 htef="http://api.jquery.com/attr / "rel="nofollow "> .attr()

http://jsfiddle.net/mattball/jjjsf/


사이드 메모로, .attr() - 또는 JavaScript가 언어로 작동하는 방식이 원격으로 사용할 수 없습니다.할당 문의 왼쪽에 함수 호출을 사용할 수 없습니다.그것은 의미가 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top