SwingWorker Example

Report a typo

What method should come to the space to complete the following code?

public class TestPane extends JPanel {

    private JLabel counterLabel;
    private int increment;
    private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);

    public TestPane() {
        setLayout(new GridBagLayout());
        counterLabel = new JLabel("...");
        add(counterLabel);

        executorService.schedule(new ExampleCounterWorker(), 1, TimeUnit.SECONDS);
    }

    public class ExampleCounterWorker extends SwingWorker<Integer, Integer> {

        @Override
        protected Integer doInBackground() throws Exception {
            for (int index = 0; index < 100; index++) {
                increment++;
                publish(increment);
                Thread.yield();
            }
            return increment;
        }

        @Override
        protected void ___________(List<Integer> integerList) {
            counterLabel.setText(Integer.toString(integerList.get(integerList.size() - 1)));
        }

        @Override
        protected void done() {
            executorService.schedule(new ExampleCounterWorker(), 1, TimeUnit.SECONDS);
        }

    }

}
Enter a short text
___

Create a free account to access the full topic