0
public void highlightThisText(){

    int delay = 1000;
    ActionListener tp = new ActionListener(){

        public void actionPerformed(ActionEvent ae){
            try{
                System.out.println();
                if(name.equals("Correct")){
                    thisPanel.getHighlighter().addHighlight(startIndex, endIndex, hl);
                }
                else{
                    anotherPanel.getHighlighter().addHighlight(startIndex, endIndex, hl);
                }

            } catch (BadLocationException ex) {
                ex.printStackTrace();
            }
        }
    };
    Timer t = new Timer(delay, tp);
    t.setRepeats(false);
    t.start();      
}

我需要我的程序进入 highlightThisText 方法,执行计时器代码,并在延迟后离开该方法。我知道我不能使用 Thread.sleep(1000); 因为这会阻止 EDT,但我在这里找不到任何其他类似问题的示例。startIndex 和 endIndex 将在方法离开后递增,这意味着正确的行将不会突出显示。

任何帮助将不胜感激。

4

0 回答 0